h
or history
command to list history#<num> <tab>
to recall the command to the command prompt without executing itInvoke-History <num>
or r <num>
to execute the specified commandnotepad (Get-PSReadlineOption).HistorySavePath
get-history | out-gridview -Passthru | invoke-history
to get and invoke command from history using a grid view. Alternatively, h | ogv -p | r
. Or, just create a function for it, function hh {get-history | out-gridview -Passthru | invoke-history}
Ctrl+r
to interactively search backward through history and Ctrl+s
to search forwardEsc
to recall command to current command lineEsc
again to remove it from the current command lineend
to select the current search resultEsc
to clear the current lineCtrl+l
to clear whole screenGet-Variable
, to list all variables in the current session$fname = "Spunky" $lname = "Violet" Write-Host "World meet $fname $lname."
$?
, exit code of last operation$ARGS
, array of arguments passed to script.$NULL
, variable that represents null value, big surprise.$true
and $false
represent the boolean valuesenv:
, pseudo drive for environment variablesExample of using Out-GridView for handy way to get output
Get-Alias | Out-GridView
Example of selecting a property from objects
$files = ls .\* -Exclude @("*.tmp") $files | select -Property FullName # Alternative: this method does not include the property header that is included with the Select-Object method above $files | foreach {$_.FullName}
if (Test-Path $file -eq $True) { Write-Host "Found a file." } else { Write-Host "No file found." }
if ($a -gt 2) { Write-Host "The value $a is greater than 2." } elseif ($a -eq 2) { Write-Host "The value $a is equal to 2." } else { Write-Host "The value $a is less than 2 or was not created or initialized." }
Set-ExecutionPolicy bypass
-executionpolicy bypass
, overrrides local system policy configuration to allow any script to run. Sometimes you just need to get things done.powershell -executionpolicy bypass -command <command text>