3

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.

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.