Four ways to remotely run an executable.
- ([WMICLASS]“PCName:Win32_Process”).create(“notepad.exe”)
- Invoke-WmiMethod –ComputerName PCName -Class win32_process -Name create -ArgumentList “notepad”
- Invoke-Command –ComputerName PCName –ScriptBlock {Start-Process notepad.exe}
- “C:\!msp\bin\PsExec.exe” @Z:\Delpoy\Software\Install.txt -s msiexec.exe /i “z:\Deploy\MSI\firefox.msi” /q
Invoke-command -scriptBlock { get-eventlog -LogName security -newest 200 } -ComputerName PC Invoke-Command {get-Process} -ComputerName $name -Credential $creds Invoke-Command {get-Process | where-object{$_.name -eq "ajeraclient"}} -ComputerName $name -Credential $creds
For Multiple PCS:
$RemoteComputers =@("PC1","PC2") ForEach ($Computer in $RemoteComputers){ Try{Invoke-Command -ComputerName $Computer -ScriptBlock {Get-ChildItem"C:\Program Files"} -ErrorAction Stop} Catch {Add-Content Unavailable-Computers.txt $Computer}}