Powershell Cheat Sheet

Powershell Cheat Sheet

PowerShell Cheat Sheet Import, Export, Convert Common cmdlets CommonCommon Aliases Aliases Export-CliXML Import-CliXML cd, chdir, sl Set-Location gcm Get-Command 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 dir, ls, gci Get-ChildItem Cmdlet Commands built into shell written in .NET del, erase, rd, ri, rm, rmdir Remove-Item Flow Control gi Get-Item Functions Commands written in PowerShell language mi, move, mv Move-Item copy, cp, cpi Copy-Item Parameter Argument to a Cmdlet/Function/Script If(){} Elseif(){ } Else{ } si Set-Item move, mv, mi Move-Item Alias Shortcut for a Cmdlet or Function while(){} ni New-Item del, rm Remove-Item Scripts Text files with .ps1 extension For($i=0; $i -lt 10; $i++){} sleep Start-Sleep rni, ren Rename-Item Applications Existing windows programs Foreach($file in dir C:\){$file.name} sajb Start-Job fFt Format-Table Pipelines Pass objects Get-process word | Stop-Process 1..10 | foreach{$_} compare, diff Compare-Object fl Format-List Ctrl+c Interrupt current command group Group-Object gcim Get-CimInstance Left/right Navigate editing cursor curl, iwr, wget Invoke-WebRequest cat, gc, type Get-Content Ctrl+left/right Navigate a word at a time Comments, Escape Characters measure Measure-Object 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 sasv Start-Service gm Get-Member Variables saps, start Start-Process sls Select-String Parameters sujb Suspend-Job cd, chdir, sl Set-Location $var = "string" Assign variable wjb Wait-Job cls, clear Clear-Host $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.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us