Solved

Service Stop Validation

Posted on 2013-05-16
2
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

630 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