Solved

Service Stop Validation

Posted on 2013-05-16
2
379 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
Comment Utility
$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
Comment Utility
ty mouseware!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now