如果继续,请检查变量Remote Process

时间:2014-08-14 16:38:03

标签: powershell

我正在尝试在控制台中显示远程计算机上的清理任务是否完成,但该进程可以运行命名为ccleaner64.exe和ccleaner.exe(自动切换,具体取决于操作系统架构)。 / p>

有一个名称有效(CCleaner.exe),但我无法想象如何过滤添加第二个名称(CCleaner64.exe)。

我需要你的建议!感谢

代码:

$computer = "PC-Dirty"

Copy-Item \\server\ccleaner \\$computer\c$ -Recurse -Force

###OWexec is to run an app as the logged on user, (http://officewarfare.net)

& \\server\owexec.exe -c $computer -k c:\ccleaner\ccsetup415\CCleaner.exe -p /AUTO -nowait 2>&1 | Out-Null

###Process checker:

$process = Invoke-WmiMethod -Class Win32_Process -Name create -ArgumentList ccleaner -ComputerName $computer
$processId = $process.ProcessId

do {(Write-Host "Waiting..."),(Start-Sleep -Seconds 1)}
until ((Get-WMIobject -Class Win32_process -Filter "Name='Ccleaner64.exe'"  -ComputerName $computer | where {$_.Name -eq "Ccleaner64.exe"}).ProcessID -eq $null)

echo "$computer Cleaned !"

Exit

我尝试添加如下:

do {(Write-Host "Waiting..."),(Start-Sleep -Seconds 1)}
until ((Get-WMIobject -Class Win32_process -Filter "Name='CCleaner64.exe'" , "Name='CCleaner.exe'" -ComputerName $computer | where {$_.Name -eq "CCleaner64.exe" -or "CCleaner.exe"}).ProcessID -eq $null)

但是我收到了这个错误:

Get-WmiObject : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Filter'. Specified method is not supported.
At line:7 char:52
+ until ((Get-WMIobject -Class Win32_process -Filter "Name='CCleaner64.exe'" , "Na ...
+                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetWmiObjectCommand

1 个答案:

答案 0 :(得分:1)

Get-WMIobject -Class Win32_process -ComputerName $computer | where {$_.Name -match "CCleaner" }应该做的伎俩