Data structure for powershell script

I am trying to write a powershell script that will take a text file (or an xml file or something that I want ti) with a list of the server name and some service names on this 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 data into a separate variable so that I can move on to other functions. if it's arguments, it seems trivial, but there should be an easy way to do this, and not use a regex for each line.

+3
source share
1 answer

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>
"@

$xml :

foreach ($server in $xml.Servers.Server) {
    foreach ($process in $server.Process) {

        # Execute your kill script here.

    }
}

kill script Invoke- Script ( PSRemoting) PsExec WMI, , . $server $process kill .

+6

Source: https://habr.com/ru/post/1757066/


All Articles