Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Service Stop Validation

Posted on 2013-05-16
2
Medium Priority
?
388 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 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

877 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