title: Powershell - Check on Remote Process, if done continue
body: <p>As part of a backup operation, I am running the 7zip command to compress a folder into a single .7z file. No problems there as I am using the <code>InVoke-WMIMethod</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>$zip = "cmd /c $irFolder\7za.exe a $somedirectory.7z $somedirectory"
  "InVoke-WmiMethod -class Win32_process -name Create -ArgumentList $zip -ComputerName $remotehost"
  </code></pre>
  
  <p>My problem comes in as my script continues, the 7za.exe process hasn't completed. I am then attempting to copy the item off of the remote system and it is either incomplete or fails.</p>
  
  <p>Can someone point me in the direction to figure out how to identify if the 7za.exe process is still running, wait until it is dead, then proceed with the rest of my script?</p>
  
  <p>I can grasp pulling the process from the remote system via...</p>
  
  <pre><code>get-wmiobject -class Win32_Process -ComputerName $remotehost | Where-Object $_.ProcessName -eq "7za.exe"}
  </code></pre>
  
  <p>Not sure how to turn that into usable info for my issue.</p>
  
  <p><strong>Answer UPDATE:</strong> (thx to nudge by @dugas)</p>
  
  <p>This will do it with some feedback for those that need it...</p>
  
  <pre><code>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)
  </code></pre>