Solved

Service Stop Validation

Posted on 2013-05-16
2
380 Views
Last Modified: 2013-05-17
Hi,
I am attempting to stop a remote service (which works great) but struggling to validate that the service has been stopped. Basically, if determined/verified to be stopped, would like to continue the script. If not stopped, then it is likely hung, and I would like to abort and LogWrite that the service was not stopped. Please advise.

$Servers = Get-content "C:\path\servers.txt
foreach ($Server in $Servers)
{
LogWrite "Issuing remote service stop command to $Server"
#Command to stop service
(Get-WmiObject Win32_Service -computername $Server -Filter "Name='Service_Name'").StopService()
LogWrite "Service stopped on $Server"
}
0
Comment
Question by:wicked212
2 Comments
 
LVL 4

Accepted Solution

by:
mouseware earned 300 total points
ID: 39173196
$Servers = Get-content "C:\path\servers.txt"
$service = "Service_Name"

foreach ($Server in $Servers) {
    LogWrite "Issuing remote service stop command to $Server"
    #Command to stop service
    (Get-WmiObject Win32_Service -computername $Server -Filter "Name='$Service'").StopService()
    $status = (Get-Service -ComputerName $server -Name $service).status
    if ($status -eq 'Stopped') {
        LogWrite "Service stopped on $Server"
        }
    else {
        #DO SOMETHING
        }
    }

Open in new window

0
 

Author Closing Comment

by:wicked212
ID: 39174710
ty mouseware!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now