Solved

Service Stop Validation

Posted on 2013-05-16
2
381 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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...
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

772 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