Powershell

Powershell – Powershell is in an interactive shell which supports scripting. You can download this from http://support.microsoft.com/kb/926139

Displays all the command available in Powershell
PS>Get-Command

CommandType Name Definition
———– —- ———-
Cmdlet Add-Content Add-Content [-Path] [-Value] <Object[…
Cmdlet Add-History Add-History [[-InputObject] ] [-Pass…

Get-Help [Name] – Help on command with description and parameter it takes
PS>Get-Help Get-Process

NAME
Get-Process

SYNOPSIS
Gets the processes that are running on the local computer.

SYNTAX
Get-Process [[-name] ] []

Get-Process -id []
Get-Process -inputObject []
….

Advertisements

Process Information

Process Information – Powershell has feature allows one to list process information, list process by name. Also one can terminate process using “Stop-Process”

PS>Get-Process -Name <program name>

Example:
PS>Get-Process -Name gvim

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
95 7 3208 9496 65 0.16 172 gvim
108 7 3696 4900 65 0.95 1456 gvim

PS>Get-Process -Verbose

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
282 20 7944 13256 105 0.95 2824 AdobeARM
95 8 1468 4404 29 0.00 2652 alg
60 5 2164 5320 54 0.09 760 atchk

— store process in a variable
PS>$process = Get-Process gvim
— print the value in the variable
PS>$process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
92 7 3128 9484 62 0.16 172 gvim
108 7 3696 4900 65 0.95 1456 gvim

— Show process with name gvim and using whatif option it let one view and the operation that will be applied on it
PS>Get-Process -Name gvim | Stop-Process -whatif
What if: Performing operation “Stop-Process” on Target “gvim (172)”.
What if: Performing operation “Stop-Process” on Target “gvim (1456)”.

— Show process with name gvim and using whatif option it let you confirm before the process is killed
PS>Get-Process -Name gvim | Stop-Process -confirm

Confirm
Are you sure you want to perform this action?
Performing operation “Stop-Process” on Target “gvim (172)”.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): N

Confirm
Are you sure you want to perform this action?
Performing operation “Stop-Process” on Target “gvim (1456)”.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): Y