0% found this document useful (0 votes)
9 views1 page

PowerShell 6 Cheat Sheet

The document provides a comprehensive overview of PowerShell cmdlets, including how to find commands, use loops and branches, and manage objects and arrays. It also covers built-in variables, common parameters, keyboard shortcuts, operators, and advanced function attributes. Additionally, it includes examples for various tasks such as file manipulation, date/time management, and string formatting.

Uploaded by

Jacob Maestas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

PowerShell 6 Cheat Sheet

The document provides a comprehensive overview of PowerShell cmdlets, including how to find commands, use loops and branches, and manage objects and arrays. It also covers built-in variables, common parameters, keyboard shortcuts, operators, and advanced function attributes. Additionally, it includes examples for various tasks such as file manipulation, date/time management, and string formatting.

Uploaded by

Jacob Maestas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

FINDING CMDLETS AND HELP USEFUL CMDLETS LOOPS & BRANCHES

Get-Command List available commands. Use -Module, -Noun, How To… Commands Loop/Branch How To Use
-Verb. Wildcards help too Zip Files Compress-Archive, Expand-Archive If/Then If ($true) { <this> }
Get-Member List properties and methods of an object Date/Time Get-Date, Set-Date, Get-TimeZone, Set-TimeZone If/Then/Else If ($true) { <this> } else { <that> }
Get-Help Help for a command. Use -Online to get latest Event Logs Get-WinEvent, New-WinEvent For For ($a=0; $a -lt 10; $a++) { <this> }
Performance Get-Counter, Export-Counter, Import-Counter Do…While Do { <this> } While ($evaluation)
Clipboard Get-Clipboard, Set-Clipboard Do…Until Do { <this> } Until ($evaluation)
PIPELINE & OBJECTS Reboot Restart-Computer While While ($evaluation) { <this> }
Send Output Out-Printer, Out-Gridview, Out-File Foreach Foreach ($a in $b) { <this $a> }
Common pattern: Get | Filter/Group/Sort | Modify/Delete/Output/Convert User Input Read-Host Switch Switch ($a) {
Use Jobs Start-Job, Stop-Job, Get-Job, Receive-Job, Remove-Job “one” { <this happens if $a is “one”> }
Where-Object Filters objects based on value of property Wait Start-Sleep “two” { <this happens if $a is “two”> }
Select-Object Choose properties of an object to include in Map Drives Get-PSDrive, New-PSDrive, Remove-PSDrive Default { <this $a is none of above>}
pipeline Navigate Get-Location, Set-Location, Test-Path }
Group-Object Group based on property values File/Folders New-Item, Get-Item, Get-ChildItem,
Sort-Object Sort results by property values Get-Content, Set-Content
Foreach-Object Act on each object in pipeline Move-Item, Rename-Item, Copy-Item, Remove-Item ARRAYS
Measure-Object Measure property values or number of objects
How To… Commands
COMMON PARAMETERS Create Array $a = @()
BUILT-IN VARIABLES Single Item Array $a = @(“one”)
-WHATIF Don’t make the changes, but output what would Item Reference $a[index] (0 is first)
$Args Arguments passed into script. -CONFIRM Prompt before making changes Range Reference $a[0..4] (Returns first 5)
$error Array of errors. $Error[0] is latest. -VERBOSE Display verbose output Last Item Reference $a[-1]
$host Details on application running PS -DEBUG Display debug-level output
$IsLinux Returns TRUE on Linux OS -ERRORACTION Override $ErrorActionPreference variable
-OUTVARIABLE Redirect output to a variable
$isMacos Returns TRUE on Mac OS
-? Display help for the cmdlet MODULES AND PACKAGES
$IsWindows Returns TRUE on Windows OS
$Profile Path to PowerShell profiles Find-Module Search PSGallery for PowerShell modules
$PSBoundParameterValues List parameters and current values. Find-Package Search PSGallery, nuget.org for software
$PSCmdlet Cmdlet/advanced function running KEYBOARD SHORTCUTS Get-Module Find modules/packages installed on system
$PSCommandPath Full path of script being run Get-Package Software installed by package management
$PSItem / $_ Current object in the pipeline Esc Clear line
Other Verbs Install, Uninstall, Update
$PSScriptRoot Directory the script is run from Tab Complete partially entered cmdlet/parameter
Register-PackageSource Allow package sources for installation
$PSVersionTable Details on PowerShell version CTRL+C Stop processing current command
Install-PackageProvider Allow additional package providers (Gist) or
Up/Down Arrow Navigate command history
specific versions
CTRL+S/CTRL+R Search forward/reverse through history
CTRL+ALT+? Show all keybindings
OPERATORS
ADVANCED FUNCTION
Arithmetic +, -, *, /, %
Assignment =, +=, -=, *=, /=, %=
STRINGS PARAMETER ATTRIBUTES
Comparison -eq, -ne, -gt, -lt, -le, -ge How To… Commands/Examples Mandatory Will prompt if missing
Wildcard Compare -like, -notlike Grep / Search Text Select-String Position Allows params in order instead
Split into array “one,two,three” -split “,” of by name
Regex Compare -match, -notmatch, -replace
Join “one”, “two”, “three” -join “, and a “ ValueFromPipeline Allows pipeline input to
Contain Comparison -in, -notin, -contains, -notcontains parameter
Replace “http://mysite.com” -replace “http:”,”https:”
Logical -and, -or, -xor, -not, ! # Decimal Places “Pi is {0:N2}” -f [Math]::Pi ValueFromPipelineByPropertyName Pipeline accepted if property
Format Currency “The price is {0:C}” -f 1.23 name matches
Type -is, -isnot, -as
Format All Caps $a = “I’m yelling”; $a.ToUpper() HelpMessage Sets param help msg
Format All Lower $a = “TOO LOUD”; $a.ToLower()
Insert Characters $a = “abcghij”; $a.Insert(3,"def")

©2019 iLovePowerShell.com

You might also like