PLEASE READ FIRST!

I've now been blogging here since 2007! ...Wow, has it been that long already?! Over the years, I've covered a wide array of subjects from scripting, troubleshooting, to the occasional hobby project. I have literally heard from thousands of you over the years with questions or even just offering me a bit of thanks!

Recently, I quit my full-time job and started work on an IT business, Rhythm IT Solutions, helping other IT departments manage their IT environments. We're offering consulting & professional services (Office 365 Migrations, Network Discovery, Firewall Management, etc...) as well as Endpoint Management (AV, Patch Management EDR, Managed Backup, etc...)



If there is something (on my blog or not) that you could use some additional help with, I would LOVE to hear from you! Please feel free to reach out to me using the contact links here or the contact form on Rhythm's website.

For those wondering, I do plan on continuing my work on the blog. So don't worry! There are plenty of Greg Strike posts yet to come! 😊 Thanks for stopping by!

PLEASE READ FIRST!




The following functions require you have Administrative privileges the to computers you are working with. These functions query the DisplayName property of the service, not the name. For instance, for the $DisplayName variable you would pass “Print Spooler” instead of “Spooler”.

I’ve used these functions to query a troublesome service that would die every once in a while. I was able to check the state and initiate a restart on the service if it were to die. The script also would send out an e-mail notifying me the services had stopped.

The following function will initiate a stop on a service and then wait 10 seconds.

Function StopService(){
     param($DisplayName, $Server)

     Write-Host("Stopping '" + $DisplayName + "' service on " + $Server + "...")

     $Filter = "DisplayName='" + $DisplayName + "'"
     $Service = Get-WmiObject -Class Win32_Service -Computer $Server -Filter $Filter

     $Null = $Service.StopService()
     Sleep 10
}

The following function will initiate a start on a service and then wait 10 seconds.

Function StartService(){
     param($DisplayName, $Server)

     Write-Host("Starting '" + $DisplayName + "' service on " + $Server + "...")    

     $Filter = "DisplayName='" + $DisplayName + "'"
     $Service = Get-WmiObject -Class Win32_Service -Computer $Server -Filter $Filter

     $Null = $Service.StartService()
     Sleep 10
}

The following function will return a System.String of a service’s current state.

Function ServiceState(){
     param($DisplayName, $Server)

     $Filter = "DisplayName='" + $DisplayName + "'"
     $Service = Get-WmiObject -Class Win32_Service -Computer $Server -Filter $Filter
     Return $Service.State
}


PLEASE READ FIRST!

I've now been blogging here since 2007! ...Wow, has it been that long already?! Over the years, I've covered a wide array of subjects from scripting, troubleshooting, to the occasional hobby project. I have literally heard from thousands of you over the years with questions or even just offering me a bit of thanks!

Recently, I quit my full-time job and started work on an IT business, Rhythm IT Solutions, helping other IT departments manage their IT environments. We're offering consulting & professional services (Office 365 Migrations, Network Discovery, Firewall Management, etc...) as well as Endpoint Management (AV, Patch Management EDR, Managed Backup, etc...)



If there is something (on my blog or not) that you could use some additional help with, I would LOVE to hear from you! Please feel free to reach out to me using the contact links here or the contact form on Rhythm's website.

For those wondering, I do plan on continuing my work on the blog. So don't worry! There are plenty of Greg Strike posts yet to come! 😊 Thanks for stopping by!

PLEASE READ FIRST!





Gregory Strike

Husband, father, IT dude & blogger wrapped up into one good looking package.