2014-09-17

Quick Tip :: Powershell and CMD one liners

List the all processes by Memory use

Windows command line (cmd.exe)
C:\> tasklist /NH | sort /+65 /R


Powershell (Start>Run type powershell and hit OK)

Get-Process | sort ws -Descending

Top 10 only
Get-Process | sort ws -Descending | select -First 10

Alternative with full *.exe name and memory use only (in Megabytes)
Get-WmiObject win32_process | sort WorkingSetSize -Descending | Select-Object -Property ProcessName,WorkingSetSize | Format-Table ProcessName,@{label="WS(MB)";Expr={[math]::truncate($_.WorkingSetSize / 1MB)}} -autosize

Alternative again, but only returning the Top 20
Get-WmiObject win32_process | sort WorkingSetSize -Descending | select -First 20 | Select-Object -Property ProcessName,WorkingSetSize | Format-Table ProcessName,@{label="WS(MB)";Expr={[math]::truncate($_.WorkingSetSize / 1MB)}} -autosize 

 
List hard drive info (Exclude Removable and CD/DVD/Blu-Ray Drives)
Powershell (Start>Run type powershell and hit OK)

Get-WmiObject -class win32_logicaldisk -Filter "DriveType != '2' AND DriveType != '5'" | Format-Table

Same thing but of a remote computer

Get-WmiObject -class win32_logicaldisk -Filter "DriveType != '2' AND DriveType != '5'" -ComputerName server.domain.net -credential domain\userid | Format-Table

Get Windows Service(s) information
PowerShell - Get status of a specific Service
(Get-Service -DisplayName 'Spoo*').status

Get status of a specific Service on a remote machine
(Get-Service -ComputerName server.domain.net -DisplayName 'IBM Cog*').status

Side note for the above 2 examples: As there is a wildcard ('*') in the name these commands may return more than one if the wildcard matches anything. I'm just lazy and don't like typing. :P

Display all services and then sort by status then name
Get-Service | Sort-Object -property `@{Expression="Status";Descending=$true}, `@{Expression="DisplayName";Descending=$false}

That's it for now. As I come across/use more I'll post them here.

No comments:

Post a Comment