小编c3u*_*faq的帖子

Powershell - 如果继续,请检查远程进程

作为备份操作的一部分,我正在运行7zip命令将文件夹压缩为单个.7z文件.我没有问题,因为我正在使用InVoke-WMIMethod.

例:

$zip = "cmd /c $irFolder\7za.exe a $somedirectory.7z $somedirectory"
"InVoke-WmiMethod -class Win32_process -name Create -ArgumentList $zip -ComputerName $remotehost"
Run Code Online (Sandbox Code Playgroud)

我的问题出现了,因为我的脚本继续,7za.exe进程尚未完成.然后我尝试从远程系统复制项目,它不完整或失败.

有人能指出我的方向,弄清楚如何识别7za.exe进程是否仍在运行,等到它死了,然后继续我的其余脚本?

我可以通过...来掌握从远程系统拉动过程

get-wmiobject -class Win32_Process -ComputerName $remotehost | Where-Object $_.ProcessName -eq "7za.exe"}
Run Code Online (Sandbox Code Playgroud)

不知道如何将其转换为我的问题的可用信息.

回答更新:(通过@dugas轻推)

这将为需要它的人提供一些反馈......

do {(Write-Host "Waiting..."),(Start-Sleep -Seconds 5)}
until ((Get-WMIobject -Class Win32_process -Filter "Name='7za.exe'" -ComputerName $target | where {$_.Name -eq "7za.exe"}).ProcessID -eq $null)
Run Code Online (Sandbox Code Playgroud)

powershell

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1