Difference between revisions of "Powershell Oneliners"
Jump to navigation
Jump to search
(Created page with " ### Get process owner ``` Get-WmiObject Win32_Process -Filter "name='sensu-agent.exe'" | Select Name, @{Name="UserName";Expression={$_.GetOwner().Domain+"\"+$_.GetOwner().Use...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | ``` | ||
+ | foreach ($i in "host1", "host2"){invoke-command -computername $i -ScriptBlock {start-service sumo-collector}} | ||
+ | ``` | ||
### Get process owner | ### Get process owner | ||
Line 5: | Line 8: | ||
Select Name, @{Name="UserName";Expression={$_.GetOwner().Domain+"\"+$_.GetOwner().User}} | | Select Name, @{Name="UserName";Expression={$_.GetOwner().Domain+"\"+$_.GetOwner().User}} | | ||
Sort-Object UserName, Name | 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 | ||
``` | ``` |
Latest revision as of 16:18, 10 March 2021
foreach ($i in "host1", "host2"){invoke-command -computername $i -ScriptBlock {start-service sumo-collector}}
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