Avatar of samiam41
samiam41
Flag 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!
PowershellWindows 10AzureWindows Server 2016

Avatar of undefined
Last Comment
samiam41

8/22/2022 - Mon
samiam41

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
samiam41

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
samiam41

ASKER

^^^Correction to the answered post


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


[additional code]

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes