PowerShell Misc Examples

By Xah Lee. Date: . Last updated: .

Misc common tasks in PowerShell.

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

Run as Admin

start powershell -Verb RunAs

or

start pwsh -Verb RunAs

Empty Trash

Clear-RecycleBin

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.

PowerShell

Practical How-To

PowerShell in Depth

Programing PowerShell

Script Examples