Using the non-aliased verbose form of the cmdlets:
$hosts = 'host1','host2','host3'
$source = '\\host0\c$\source'
$dest = 'c:\dest'
$executable = 'C:\Program Files (x86)\Notepad++\notepad++.exe'
Invoke-Command -Computer $hosts -ScriptBlock {
Get-Process | Where-Object Path -eq $using:executable | Stop-Process -Force
Copy-Item -Path $using:source -Destination $using:dest
}
Explanation:
Line 1-4: Set up variables to make the script more explanatory. Line 1 defines an array (the "," operator)
Line 6: Invoke-Command takes an array of (remote) hosts (the -Computer parameter) to execute the script block (the -ScriptBlock parameter).
Lines 7-9: The script to execute at each host simultaneously (the Invoke-Command executes the scripts in parallel at each host)
Line 7: Get the process list (Get-Process), pipe through the filter (Where-Object) which selects only the process(es) executing the desired executable, pipe those processes to the Stop-Process cmdlet which will forcably stop the process.
Line 8: Copy files from the desired source at an UNC path to the local machine at the destination
Now, the above script was the canonical way, using the long form. For casual scription, I could have written just this:
$hosts = 'host1','host2','host3'
$executable = 'C:\Program Files (x86)\Notepad++\notepad++.exe'
icm $hosts { ps | ? Path -eq $using:executable | kill -f; cp \\host0\c$\source c:\dest }