Search This Blog

06 July 2011

PowerShell script to restart Windows (AOS) services remotely


Just a small script to restart a list of Windows-services (download here). It checks that they are stopped and kills them if they cannot be stopped and then starts them. If there are any errors, an email is sent and the user is informed about the progress in the tray-bar. All this is configurable in an Xml-file. It's a small script and should only be used as an example of how the PowerShell can be useful for the daily business (please understand that I don't publish the final version):

  • stopping and starting services remotely
  • killing a process remotely
  • getting ProcessId from service-name
  • sending a mail
  • executing WMI queries on remote machines
  • pinging machines
  • Info-bubble in the tray bar
  • creating and writing into EventLogs
  • handling exceptions
  • working with Xml-files
  • passing parameter to a function
  • working with ref-variables

Update: (09/07/11) Updated script with some fixes and changes in the behavior.
Update: (10/07/11)  As this was my first experience with PowerShell scripting, I rewrote the script with all what I learned during these days. The script does now restart remotely in a controlled way the services and tracks all info about the executed activities and anomalies during this process.
Update: (23/07/11)  Still novice with PowerShell... :-( Refactored the code so that it is now using the pipeline instead of referenced arguments.

4 comments:

  1. Hi Florian.
    Great script, I've put it into production and am using it to restart aos-services each night.

    Is it possible to use the script to only stop the aos-services as well? To save som time on stopping 16-aos-services accross 4 servers.
    Trond

    ReplyDelete
  2. hey florian

    the download link is not available. can you repost it please /

    Thanks

    ReplyDelete
  3. Hello, should work now. It's like all other ressources published on SkyDrive.

    ReplyDelete
  4. Great and that i have a super give: How Much Budget For House Renovation house renovation spreadsheet

    ReplyDelete