title: Check if process is running on multiple remote computers and copy a file if process is NOT running, keep list of those which succeeded
body: <p>I need to copy a file to multiple computers, but can only do so if a particular app (process) is not running.</p>
  <p>I know I can use Invoke-Command to run a script (scriptblock) on a list of machines.</p>
  <p>But how can I check if process is running on the machine and then only copy file if it is not running.</p>
  <p>So that at the end of running against a load of computers I can easily see those which succeeded e.g. process was not running and file was copied</p>
  <p>Thanks</p>
  <p>UPDATE:</p>
  <p>I am assuming something like this will do the first bits of what I am asking, but how to visually show or log success or failure so I know which computers have been done - doesn't need to be anything fancy, even if simply a variable that holds computername of those where process wasn't running and file was copied okay</p>
  <pre><code>Invoke-Command -ComputerName PC1, PC2, PC3 -ScriptBlock {
  
  If ((Get-process -Name notepad -ea SilentlyContinue) -eq $Null){
  
     Copy-Item -Path &quot;\\server01\c$\test\file.txt&quot; -Destination &quot;C:\test\file.txt&quot; -Force
  
  }
  
  }
  </code></pre>