pedaleo
pedaleo

Reputation: 411

Check on variable Remote Process, if done continue

I'm trying to display in console if the cleaning task on a remote computer is done or not , but the process can run named as ccleaner64.exe and ccleaner.exe (automaticly switches, depending on the OS archiquecture).

With one name works(CCleaner.exe) but I can't figure how to Filter adding a second name(CCleaner64.exe).

I need your suggiestions ! thanks

code:

$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

I tried to add like:

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)

but I got this error:

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

Upvotes: 0

Views: 132

Answers (1)

Loïc MICHEL
Loïc MICHEL

Reputation: 26170

Get-WMIobject -Class Win32_process -ComputerName $computer | where {$_.Name -match "CCleaner" } should do the trick

Upvotes: 1

Related Questions