jfgray
asked on
Wait for exit
I have the folling script that runs a batch file on a remote computer
$command = "c:\hello.bat"
$process = [WMICLASS]"\\$MachineName\ ROOT\CIMV2 :win32_pro cess"
$result = $process.Create($command)
How can I pause or wait to continue until this has completed?
$command = "c:\hello.bat"
$process = [WMICLASS]"\\$MachineName\
$result = $process.Create($command)
How can I pause or wait to continue until this has completed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yes, if after the process ends, the get-process will error because it is no longer running.
To suppress the error message, change the $ErrorActionPreference to “silentlycontinue”
$ErrorActionPreference = “silentlycontinue”
To suppress the error message, change the $ErrorActionPreference to “silentlycontinue”
$ErrorActionPreference = “silentlycontinue”
ASKER
THANK YOU ! ! !
ASKER
Cannot find a process with the name "cmd". Verify the process name and call the cmdlet again.
At :line:50 char:41
+ do {Start-Sleep -s 1} While ((Get-Process <<<< -Name cmd -computername $MachineName | Measure-Object).count -gt 0)
Is this expected ?