Xml config file and Powershell

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.

Comments are closed.
How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site