Difference between revisions of "Global Knowledge PowerShell Training"
(→Objects) |
(→Objects) |
||
Line 64: | Line 64: | ||
== Objects == | == Objects == | ||
− | get-process | | + | get-process | get-member |
Get-Member will output the member properties for an Object | Get-Member will output the member properties for an Object | ||
Line 76: | Line 76: | ||
----- | ----- | ||
+ | dir | get-member | ||
+ | ----- | ||
+ | get-service | format-table status,name | get-member | ||
+ | Output references the output of the Format-Table object rather than the Get-Service object. | ||
+ | |||
+ | Format-Table/Format-List should usually be the LAST command in a Pipe Line. | ||
+ | |||
+ | ----- | ||
+ | |||
+ | get-service | sort-object - property name | ||
+ | |||
+ | get-process | sort Name,ID | ||
+ | |||
+ | get-process | sort VM -Descending (or -desc, abbreviations work for more items as long as they are unique) | ||
+ | |||
+ | ----- | ||
+ | |||
+ | notepad;notepad;notepad | ||
+ | |||
+ | WIll open three instances of NotePad.exe | ||
+ | |||
+ | get-process | sort Name,ID | format-list | ||
+ | |||
+ | ----- | ||
+ | |||
+ | get-process | measure -property VM | ||
+ | |||
+ | get-process | measure -property VM -Sum -Average -Maximum -Minimum | ||
+ | |||
+ | ----- | ||
+ | |||
+ | Select-Object | ||
+ | |||
+ | get-process | ft Name,VM,PM | ||
+ | |||
+ | get-process | format-table Name,VM,PM | ||
+ | |||
+ | Can't sort this by VM now because it's been destroyed by the Format-Table command. | ||
+ | |||
+ | You have to change how you sort. | ||
+ | |||
+ | Get-Process | Select-Object Name,VM,PM | Sort VM -desc | ||
+ | |||
+ | The Select-Object command extracts the Name,VM,PM objects and preserves them for future actions. | ||
+ | |||
+ | ----- | ||
+ | |||
+ | get-process | sort vm -desc | select-object name,vm,pm -First 10 | ||
+ | |||
+ | Top 10 memory consumers. | ||
+ | |||
+ | ----- | ||
+ | |||
+ | Get-Process | Select-Object Name,@{l="VM(MB)";e={$_.vm / 1mb}} | ||
+ | |||
+ | ----- | ||
[[Category:Training]] | [[Category:Training]] | ||
[[Category:Work]] | [[Category:Work]] | ||
[[Category:PowerShell]] | [[Category:PowerShell]] | ||
[[Category:Scripting]] | [[Category:Scripting]] |
Revision as of 20:30, 8 June 2015
General Information about PowerShell
Notes
Different versions of PowerShell are available for different OS's. Microsoft is using PowerShell as a way to drive people to upgrade to the latest version of Windows. Newer versions of Powershell work better with Newer versions of Microsoft Windows.
Two versions of the Powershell interface.
- Console
- Basic Command-Line
- Maximum support for PowerShell
- Minimal editing capabilities
- ISE
- Script Editor and Console Combination
- Some PowerShell features not supported
- Rich editing cap
- Third Party hosting apps/Editors
- Variable Features and Pricing
- PowerGUI
help dir -Online
help dir -ShowWindow
The "-WhatIf" option will allow you to "Dry Run" a command that might modify something on the system.
The "-Confirm" option allows for a Y/N query per item for any command that MODIFIES the system.
get-command
get-command | measure-object
get-command | out-gridview
Show-Command Get-ChildItem
The "back tick" character (above the TAB key) is the "Line Continued Below" reference.
help dir `
-ShowWindow
is the same as
help dir -ShowWindow
get-service | sort-object -Property Status | Out-File Service.txt
same as ...
get-service | sort-object -Property Status > C:\Service.txt
get-service | sort-object -Property Status | Out-File Service.txt -Append
same as ...
get-service | sort-object -Property Status >> C:\Service.txt
Objects
get-process | get-member
Get-Member will output the member properties for an Object
get-service | Format-Table *
get-service spooler | Format-list
dir | get-member
get-service | format-table status,name | get-member
Output references the output of the Format-Table object rather than the Get-Service object.
Format-Table/Format-List should usually be the LAST command in a Pipe Line.
get-service | sort-object - property name
get-process | sort Name,ID
get-process | sort VM -Descending (or -desc, abbreviations work for more items as long as they are unique)
notepad;notepad;notepad
WIll open three instances of NotePad.exe
get-process | sort Name,ID | format-list
get-process | measure -property VM
get-process | measure -property VM -Sum -Average -Maximum -Minimum
Select-Object
get-process | ft Name,VM,PM
get-process | format-table Name,VM,PM
Can't sort this by VM now because it's been destroyed by the Format-Table command.
You have to change how you sort.
Get-Process | Select-Object Name,VM,PM | Sort VM -desc
The Select-Object command extracts the Name,VM,PM objects and preserves them for future actions.
get-process | sort vm -desc | select-object name,vm,pm -First 10
Top 10 memory consumers.
Get-Process | Select-Object Name,@{l="VM(MB)";e={$_.vm / 1mb}}