Xml – How to get parameters from XML and execute the list of exe

powershellpowershell-2.0xml

I am executing an exe with parameters like follows (I am using powershell).

$path="C:\Program Files\RobWare\RVTools"


$VCServer="15.3.3.3"
$VCServer2="16.5.4.4"
$AttachmentFile=$vcserver.xls

&"$path\rvtools.exe" -s $VCServer -u user-p password-c ExportAll2xls -d $AttachmentDir -f $AttachmentFile
&"$path\rvtools.exe" -s $VCServer2 -u user2 -p password123 -c ExportAll2xls -d $AttachmentDir -f $AttachmentFile

As i am having many VCserver, I thought it is better to have XML file and then execute this exe for all the VCserver.

I would like to write an xml file where all the parameters would be specified like follows.

<Host>
  <IP>15.3.3.3</IP>
  <User>user</User>
  <Password>password</Password>
</Host>

<Host>
  <IP>16.3.3.3</IP>
  <User>user</User>
  <Password>password</Password>
</Host>

Then call the exe and pass this parameters from XML. How to do it ?

Best Solution

using a XML file like this :

<rvToolsParams>
  <Host> 
    <IP>15.3.3.3</IP> 
    <User>user</User> 
    <Password>password</Password> 
  </Host> 
  <Host> 
    <IP>16.3.3.3</IP> 
    <User>user</User> 
    <Password>password</Password> 
  </Host>
</rvToolsParams>

Called here under rvtools.xml you can also do these ways :

$xml = [XML](Get-Content C:\temp\rvtools.xml)
$xml.rvToolsParams.host

IP                                      User                                    Password
--                                      ----                                    --------
15.3.3.3                                user                                    password
16.3.3.3                                user                                    password

$xml.rvToolsParams.host | % {& "$path\rvtools.exe" -s $_.IP -u $_.User -p $_.Password -c ExportAll2xls -d $AttachmentDir -f $AttachmentFile }
15.3.3.3
user
password
16.3.3.3
user
password

Or in a script

foreach ($host in $xml.rvToolsParams.host)
{
  $host.IP
  ...
}