Friday, July 9, 2010

Stop/Start or Enable/Disable Service – PowerShell Script

You can use the following PowerShell script to Start, Stop, Enable or Disable Windows services on a remote machine. An input file can be used to provide the computer names.



Updated Script -


Hi Santhosh,
I'm from Brazil and i need to start mom service in more than 300 machine after patched them.
I'm new in scripts so, if i save this line as txt file and a csv file. That's all i need?


This is a PowerShell script so you need to rename the txt file extension to .PS1

Input.csv file contains all computer names.

Also, I have updated script on the following location. You can enter additional credentials if needed.

Hi Siva,

This is Sunil from Toronto, need help in writing a script
1. Services to be stopped and upon completion need to create a file (services stopped) in a folder i point (Stop).
2. Also need to automatically start the services up on reading a file (Services started)in a folder i point (Start)

Is this possible? help me.

Take a look at the following updated script.

I must be doing something wrong when I use your scripts.
I changed the $service = "regsvc"
I removed the first two green lines since I'm waiting to start the service.
Also, when I first ran the script I received an error "Cannont validate argument on parameter 'ComputerName'. So I assumed I had to put ComputerName as the heading in the input.csv.

When I re-ran the script I get the following error "The RPC server is unavailable". (Line 9 char: 16)

Then I noticed you updated the script to add the credentials.
I still got the above error, plus "You cannot call a method on a null-valued expression"

So I must be doing something extremely wrong!

Please help.


Yes. The header must be ComtuterName.

>> The RPC server is unavailable

Sounds like script can’t access the remote computer. Can you browse \\computer\admin$? If not, you won’t be able to manage this computer remotely.

How would I run this like a shortcut (want to place a shortcut in my desktop that runs this script)? If I double click it, it opens up in Notepad, only when I right click, then select Run with Powershell, than it runs. Also, it closes so fast that you cannot view any messages.

Post a Comment

Popular Posts


Twitter Delicious Facebook Digg Stumbleupon Favorites More