PowerShell Misc Examples

By Xah Lee. Date: . Last updated: .

Misc common tasks in PowerShell.

clear, cls
(Clear-Host) Clear screen.
(Move-Item) Move a file/dir to another dir.
(Write-Output) Print to next pipe or screen.
(Get-Process) Lists proceses.
(Stop-Process) Stop one process or more.

Run as Admin

start powershell -Verb RunAs


start pwsh -Verb RunAs

Empty Trash


Clear Shell Command History

Set-Content (Get-PSReadlineOption).HistorySavePath -value ""

the (Get-PSReadlineOption).HistorySavePath returns the PowerShell command history file at ~\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

start app, launch app, run script/code

invoke-item (alias ii)
Start default app on a file or app, e.g. open default app on a image file, pdf file, folder path.
ii photo.jpg
ii ~/
start-process (alias saps, start)
Start a processes. e.g. launch notepad, browser.
start notepad
start chrome
Start-Job (alias sajb)
Start a PowerShell background job.
invoke-expression (alias iex)
run a PowerShell expression from a string. Normally, a string is printed as is. This is similar to eval in many langs.
invoke-command (alias icm)
run a command.


Practical How-To

PowerShell in Depth

Programing PowerShell

Script Examples