I am trying to disable a service running on 250+ PCs. I would like to have a PowerShell script I can execute on a random PC in the network and let it disable a service on every PC I specify in an txt file. It's always the same service. The script should also ask for the credential of the PC that it is trying to connect to.

This is a Script to set DNS on every PC in computer.txt. It asks me for the "administrator" password for every PC.

9 Replies

You've got the basics of it there already, use Get-Content to read in the text file to a variable then run a foreach loop over the variable to loop through each PC and in the loop use Stop-Service and the name of the service. I don't remember if Stop-Service works remotely but if not then you can use Invoke-Command or a remote session to handle that.

If you get stuck with any of the commands then Get-Help will be your friend.

Just out of curiosity, but do you not have an account that has domain level admin priv to access those pc's? As for get-service not having a way to use credentials, you could get around that with ps remoting, such as enter-pssession