Remote Execution

By | February 19, 2020

Four ways to remotely run an executable.

  1. ([WMICLASS]“PCName:Win32_Process”).create(“notepad.exe”)
  2. Invoke-WmiMethod –ComputerName PCName -Class win32_process -Name create -ArgumentList “notepad”
  3. Invoke-Command –ComputerName PCName –ScriptBlock {Start-Process notepad.exe}
  4. “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}}