data structure for powershell script
I am trying to write a powershell script that 开发者_开发技巧will take in a text file (or xml file or whatever I want ti to be) with a list of servername and some service names on that server to stop. I can get powershell to read in a line from a text file, but I can't figure out how to get powershell to import the data into seperate variable for me to pass on to other functions. if this were arguemnts it seems trivial but there must be a simple way to do that rather than me using a regex on each line.
Consider the XML below:
$xml = [xml]@"
<Servers>
<Server name="SERVER1">
<Process>Process1</Process>
<Process>Process2</Process>
</Server>
<Server name="SERVER2">
<Process>Process3</Process>
</Server>
</Servers>
"@
You could process the $xml
variable like so:
foreach ($server in $xml.Servers.Server) {
foreach ($process in $server.Process) {
# Execute your kill script here.
}
}
For a kill script on remote machines, you could use the Invoke-Script cmdlet (requires PSRemoting be enabled), or PsExec, or WMI, whichever you're most comfortable with. The $server
and $process
variables will be required to execute the kill against the correct process on the correct server.
精彩评论