
Xml config file and Powershell
To create “clean” scripts, you have to use a config file that contains all parameters such as server name, accounts, etc… That kind of file is frequently named “config.xml”
It is really a basic xml file :
<?xml version="1.0"?> <Settings> <Params> <Serverslist>serverlist.txt</Serverslist> </Params> <Mail> <Mailer>mailer.contenso.local</Mailer> <DestMail>destmail@contenso.local</DestMail> <SourceMail>experd@contenso.local</SourceMail> </Mail> </Settings>
Then, in the powershell, at the top of the script, you just have to place that kind of code :
$ConfigFile = Get-Content "config.xml" $ServerslistFile = $configfile.Settings.Params.Serverslist $Mailer=$configfile.Settings.Mail.Mailer $DestMail=$configfile.Settings.Mail.DestMail $SourceMail=$configfile.Settings.Mail.SourceMail
And that’s it ! It become really easy to add this script at a client’s or another.