We help IT Professionals succeed at work.

PS script (check service status, wait for service to be stopped)

Hey Experts.  I need to copy data from a directory on a server (serverA) but a Windows service on the server needs to be stopped before the data is copied.  Not sure how to get the script to check for the Windows service (say spooler) to be stopped before the script continues on.  Thank you in advance for any help!
Comment
Watch Question

Author

Commented:

*I'm running the script as a scheduled task on my PC so the commands would need to be remote (I'm guessing)

Commented:

$svc = Get-Service spooler
$svc.WaitForStatus('Stopped')

Author

Commented:

^^^Correction to the answered post


$svc = Get-Service -computername serverA -name spooler
$svc.WaitForStatus('Stopped')


[additional code]

Explore More ContentExplore courses, solutions, and other research materials related to this topic.