Powershell Oneliners

From UVOO Tech Wiki
Revision as of 19:49, 4 March 2021 by Busk (talk | contribs)
Jump to navigation Jump to search

Get process owner

Get-WmiObject Win32_Process -Filter "name='sensu-agent.exe'" |
Select Name, @{Name="UserName";Expression={$_.GetOwner().Domain+"\"+$_.GetOwner().User}} |
Sort-Object UserName, Name

Remote command execution

Invoke-Command -ComputerName $hostname -f C:\tmp\myscript.ps1
Invoke-Command -ComputerName $host -ScriptBlock { Get-ChildItem C:\ } -credential $username