Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

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!
Avatar of samiam41
samiam41
Flag of United States of America image

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of samiam41
samiam41
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

^^^Correction to the answered post


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


[additional code]