0% found this document useful (0 votes)
654 views

Comparitech Powershell Cheatsheet

The document provides a cheat sheet of common PowerShell commands organized into categories such as importing and exporting, flow control, comments and escape characters, parameters, variables, arrays, and help. It lists aliases and brief descriptions for many cmdlets used for working with files, processes, services, jobs, objects, and more. The cheat sheet serves as a quick reference guide for PowerShell syntax and the most frequently used commands.

Uploaded by

elisa
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)
654 views

Comparitech Powershell Cheatsheet

The document provides a cheat sheet of common PowerShell commands organized into categories such as importing and exporting, flow control, comments and escape characters, parameters, variables, arrays, and help. It lists aliases and brief descriptions for many cmdlets used for working with files, processes, services, jobs, objects, and more. The cheat sheet serves as a quick reference guide for PowerShell syntax and the most frequently used commands.

Uploaded by

elisa
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

PowerShell Cheat Sheet Import, Export, Convert

Export-CliXML Import-CliXML
Common cmdlets CommonCommon
Aliases

gcm
Aliases
Get-Command
cd, chdir, sl Set-Location
ConvertTo-XML ConvertTo-HTML cat, gc, type Get-Content foreach,% Foreach-Object
Export-CSV Import-CSV ac Add-Content sort Sort-Object
ConvertTo-CSV ConvertFrom-CSV sc Set-Content where, ? Where-Object
Basic Commands copy, cp, cpi Copy-Item diff, compare Compare-Object
del, erase, rd, ri, rm, rmdir Remove-Item dir, ls, gci Get-ChildItem
Cmdlet Commands built into shell written in .NET Flow Control mi, move, mv Move-Item gi Get-Item
Functions Commands written in PowerShell language
si Set-Item copy, cp, cpi Copy-Item
Parameter Argument to a Cmdlet/Function/Script If(){} Elseif(){ } Else{ }
ni New-Item move, mv, mi Move-Item
Alias Shortcut for a Cmdlet or Function while(){}
sleep Start-Sleep del, rm Remove-Item
Scripts Text files with .ps1 extension For($i=0; $i -lt 10; $i++){}
sajb Start-Job rni, ren Rename-Item
Applications Existing windows programs Foreach($file in dir C:\){$file.name}
compare, diff Compare-Object fFt Format-Table
Pipelines Pass objects Get-process word | Stop-Process 1..10 | foreach{$_}
group Group-Object fl Format-List
Ctrl+c Interrupt current command
curl, iwr, wget Invoke-WebRequest gcim Get-CimInstance
Left/right Navigate editing cursor
Comments, Escape Characters measure Measure-Object cat, gc, type Get-Content
Ctrl+left/right Navigate a word at a time
nal New-Alias sc Set-Content
Home / End End Move to start / end of line #Comment Comment
rvpa Resolve-Path h, history, ghy Get-History
Up/down Move up and down through history <#comment#> Multiline Comment
rujb Resume-Job ihy, r Invoke-History
Insert Toggles between insert/overwrite mode "`"test`"" Escape char `
set, sv Set-Variable gp Get-ItemProperty
F7 Command history in a window `t Tab
shcm Show-Command sp Set-ItemProperty
Tab / Shift-Tab Command line completion `n New line
sort Sort-Object pwd, gl Get-Location
` Line continue gm Get-Member
sasv Start-Service
Variables saps, start Start-Process sls Select-String
Parameters sujb Suspend-Job cd, chdir, sl Set-Location
$var = "string" Assign variable cls, clear Clear-Host
wjb Wait-Job
$a,$b = 0 or $a,$b = 'a','b' Assign multiple variables -Confirm Prompt whether to take action ?, where Where-Object
$a,$b = $b,$a Flip variables -WhatIf Displays what command would do echo, write Write-Output Arrays Objects
$var=[int]5 Strongly typed variable
Assignment, Logical, Comparison $arr = "a", "b" Array of strings
Help $arr = @() Empty array
=, +=, -=, ++,-- Assign values to variable $arr[5] Sixth array element
Get-Command Get all commands -and, -or, -not,! Connect expressions / statements $arr[-3..-1] Last three array elements
Get-Command -Module RGHS Get all commands in RGHS module -eq, -ne Equal, not equal $arr[1,4+6..9] Elements at index 1,4, 6-9
Get-Command Get-p* Get all commands starting with get-p -gt, -ge Greater than, greater than or equal $arr[1] += 200 Add to array item value
Get-help get-process Get help for command -lt, -le Less than, less than or equal $z = $arA + $arB Two arrays into single array
Get-Process | Get-Member Get members of the object -replace “Hi” -replace “H”, “P” [pscustomobject]@{x=1;z=2} Create custom object
Get-Process| format-list -properties * Get-Process as list with all properties -match, -notmatch Regular expression match (Get-Date).Date Date property of object
-like, -notlike Wildcard matching
-contains, -notcontains Check if value in array
Scripts -in, -notin Reverse of contains, notcontains. Writing output and reading
Set-ExecutionPolicy -ExecutionPolicy Bypass Set execution policy to allow all scripts "This displays a string" String is written directly to output
."\\c-is-ts-91\c$\scripts\script.ps1” Run Script.PS1 script in current scope Write-Host "color" -ForegroundColor Red -NoNewLine String with colors, no new line at end
&"\\c-is-ts-91\c$\scripts\script.ps1" Run Script.PS1 script in script scope $age = Read-host "Please enter your age" Set $age variable to input from user
.\Script.ps1 Run Script.ps1 script in script scope $pwd = Read-host "Please enter your password" -asSecureString Read in $pwd as secure string
$profile Your personal profile that runs at launch Clear-Host Clear console

You might also like