我正在尝试构建一个计算机名列表,然后可以使用它来调用另一个power shell命令. 手动流程: $Type1Machines="Machine1","Machine2","Machine3","Machine4"Invoke-command {Powershell.exe C:\myscript.ps1 Type1} -compute
手动流程:
$Type1Machines="Machine1","Machine2","Machine3","Machine4" Invoke-command {Powershell.exe C:\myscript.ps1 Type1} -computername $Type1Machines
我已经在XML文件中有关于“Type1”机器名称的信息(MachineInfo.xml)
<Servers> <Type1> <Machine><Name>Machine1</Name> <MachineOS>WinXP</MachineOS></Machine> <Machine><Name>Machine2</Name> <MachineOS>WinServer2003</MachineOS></Machine> <Machine><Name>Machine3</Name> <MachineOS>WinServer2003</MachineOS></Machine> <Machine><Name>Machine4</Name><MachineOS>WinServer2003</MachineOS></Machine> </Type1> </Servers>
我正在尝试编写一个脚本,它可以拉出“Type1”的机器名列表并构造下面的url.
$Type1Machines=”Machine1″,”Machine2″,”Machine3″,”Machine4″
到目前为止,我已经到了可以从xml获取机器名列表的地步
#TypeInformation will be pass as an argument to the final script $typeinformation = 'Type1' $global:ConfigFileLocation ="C:\machineinfo.xml" $global:ConfigFile= [xml](get-content $ConfigFileLocation) $MachineNames = $ConfigFile.SelectNodes("Servers/$typeinformation") $MachineNames
输出:
Machine ------- {Machine1, Machine2, Machine3, Machine4}
现在我如何使用上面的输出并构建下面的url?
$Type1Machines = “MACHINE1”, “机器2”, “Machine3”, “Machine4”
任何帮助表示赞赏.谢谢你的时间!
我假设您希望将每个机器名称值放入数组(与invoke-commmand一起使用):[string[]]$arr = @() # declare empty array of strings $ConfigFile.SelectNodes("/Servers/$typeInformation/Machine") | % {$arr += $_.name}