Useful List of PowerShell Commands

This article shows a convenient list of PowerShell Commands for your quick reference. This contains major Cmdlets, Descriptions, and Examples. Please refer to Microsoft Web Page to get more detailed information per each Cmdlet.

File or Directory Cmdlets

CmdletDescriptionExample
New-Item

Copy-Item

Get-ChildItem

Move-Item

Remove-Item  

Rename-Item
Create a new item

Copy an item from a specific location to another

Gets the items and child items in the location

Move an item from one location to a different one

Removes files and folders

Rename an item
New-Item -Path “c:\” -Name “logfiles” -ItemType “directory”

Copy-Item -Path “C:\Logfiles\*” -Destination “C:\Drawings” -Recurse

Get-ChildItem -Path “.\*.txt” -Recurse | Move-Item -Destination “C:\TextFiles”

Get-ChildItem * -Include *.csv -Recurse | Remove-Item

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace ‘.txt’,’.log’ }

Write Cmdlets

CmdletDescriptionExample
Write-Output

Write-Host

Write-Information

Write-Progress

Write-Verbose

Write-Warning

Write-Error
Writes the specified objects to the pipeline

Writes output to console

Specifies how PowerShell handles information data for a command

Displays a progress bar within a PS command window

Write more verbose than Normal

Writes a warning message

Writes an error message
$P = Get-Process
Write-Output $P


Write-Host “no newline test ” -NoNewline

Write-Information -MessageData “Processes starting with ‘P'” -InformationAction Continue

Write-Progress -Activity “Search in Progress” -Status “$i% Complete:” -PercentComplete $i

Write-Error -Message “Error: Too many input values.” -Category InvalidArgument

Read and Out Cmdlets

CmdletDescriptionExample

Read-Host

Out-File

Out-String

Out-GridView

Out-Printer
Reads a line of input from the console

Sends output to a file

Outputs input objects as a string

Sends output to an interactive table

Sends output to a printer
$pwd_string = Read-Host “Enter a Password” -MaskInput

Get-Process | Out-File -FilePath .\Process.txt


Out-String -InputObject $C -Width 100

Get-Process | Out-GridView

Write-Progress -Activity “Search in Progress” -Status “$i% Complete:” -PercentComplete $i

Object Cmdlets

CmdletDescriptionExample
ForEach-Object

Compare-Object

New-Object

Select-Object

Sort-Object

Where-Object
Performs an operation against each item in a collection

Compare two objects

Creates an instance of a .NET Framework or COM object.

Select objects as well as their properties

Sorts objects by property values

Selects objects from a collection based on their property values.
1..3 | ForEach-Object -Parallel { Write-Error “Error: $_” }

$objects = @{ ReferenceObject = (Get-Content -Path C:\Test\Testfile1.txt)
DifferenceObject = (Get-Content -Path C:\Test\Testfile2.txt) }
Compare-Object @objects -ExcludeDifferent

$Objshell = New-Object -COMObject “Shell.Application”


Get-Process | Select-Object -Property ProcessName, Id, WS

Get-ChildItem -Path C:\Test -File | Sort-Object -Property Length

Get-Process | Where-Object {$_.ProcessName -Match “^p.*”}

Location Cmdlets

CmdletDescriptionExample
Get-Location

Set-Location

Pop-Location

Push-Location
Fetches information about your current location

Set your current working location to a specified location

Set to the location that was pushed to the
stack most recently

Appends the current location to the top of a location stack
Writes a warning message
Set-Location C:\Windows

Push-Location ~ -StackName Stack2

Pop-Location -StackName Stack2

Registry Cmdlets

CmdletDescriptionExample
New-ItemProperty

Get-ItemProperty

Set-ItemProperty

Copy-ItemPropery

Move-ItemProperty

Rename-ItemProperty

Remove-ItemProperty

Clear-ItemProperty
Adds a new registry entry

Fetches the properties of the item

Creates or changes the value

Copies a property and value

Move a property from A to B

Rename an item’s property

Delete a property and its value

Clears the value
Get-Item -Path “HKLM:\Software\MyCompany” | New-ItemProperty -Name NoOfLocations -Value 3

Get-ItemProperty -Path “HKLM:\Software\Test”

Set-ItemProperty -Path “HKLM:\Software\Test” -Name “Employee” -Value 823

Copy-ItemProperty -Path “MyApplication” -Destination “HKLM:\Software\MyApplicationRev2” -Name “MyProperty”

Move-ItemProperty “HKLM:\Software\MyCompany\MyApp” -Name “Version” -Destination “HKLM:\Software\MyCompany\NewApp”

Clear-ItemProperty -Path “HKLM:\Software\MyCompany\MyApp” -Name “Options”

Process Cmdlets

CmdletDescriptionExample
Get-Process

Start-Process

Stop-Process

Wait-Process

Fetches a list of processes that are running

Launches one or more local processes

Stop one or more running processes

Waits for the processes to be stopped
Get-Process explorer | Format-List *

Start-Process -FilePath “$env:comspec” -ArgumentList “/c dir”

Stop-Process -Name “notepad”

Wait-Process -Name notepad -Timeout 30

Service Cmdlets

CmdletDescriptionExample
Get-Service

Start-Service

Stop-Service
Lists all the services

Start one or more stopped services

Stops one or more running services
Get-Service -Name “iisadmin” | Stop-Service -Force

Start-Service -DisplayName *remote* -WhatIf

Job Cmdlets

CmdletDescriptionExample
Get-Job

Receive-Job

Remove-Job

Resume-Job

Start-Job

Stop-Job

Wait-Job
Retrieves a list of all the background jobs that are running in your session

Fetches the results of current session background jobs

Delete a Windows PowerShell background job

Restart a job that was suspended

Starts a background job

Stops a PowerShell background job

Waits until PowerShell jobs running in the session
$job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1

Receive-Job $job

$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog System} -AsJob $j | Stop-Job -PassThru


Wait-Job -Name “DailyLog” -Timeout 120

Event Cmdlets

CmdletDescriptionExample
Get-Event

New-Event

Remove-Event

Wait-Event

Gets the events in the event queue

Create a new event

Deletes events from the event queue

Waits until a particular event is raised before continuing to run
New-Event -SourceIdentifier Timer -Sender windows.timer -MessageData “Test”

Remove-Event -SourceIdentifier “ProcessStarted”


Wait-Event -SourceIdentifier “ProcessStarted”

Execute Cmdlets

CmdletDescriptionExample
Invoke-Command

Invoke-Expression

Invoke-Item

Runs the command on local and remote computers.

Runs commands or expressions

Performs the default action on a specified item
Invoke-Command -ComputerName Server02 -ScriptBlock {$p = Get-Process PowerShell}

$Command = ‘Get-Process | where {$_.cpu -gt 1000}’

Invoke-Expression $Command

Invoke-Item “C:\Test\aliasApr04.doc”

Web Access Cmdlets

CmdletDescriptionExample
Invoke-RestMethod

Invoke-WebRequest

Sends either an HTTP/HTTPS request to a RESTful web service

Retrieves content from a webpage on the Internet

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body

$Response = Invoke-WebRequest -Uri “www.microsoft.com/unkownhost”

File Content Cmdlets

CmdletDescriptionExample
Add-Content

Get-Content

Set-Content

Clear-Content
Appends content to a file.

Displays the contents of a file

Allows you to replace a file’s contents with contents that you specify

Clears the contents of an item without deleting the actual item
Add-Content -Path .\1.txt -Value (Get-Content -Path .\2.txt)

(Get-Content -Path .\Notice.txt) | ForEach-Object {$_ -Replace ‘Warning’, ‘Caution’} | Set-Content -Path .\Notice.txt

Session Connection Cmdlets

CmdletDescriptionExample
New-PSSession

Get-PSSession

New-PSSessionConfigurationFile

Receive-PSSession

Remove-PSSession

Disconnect-PSSession
Establishes a persistent connection

Retrieves a list of PS sessions

Creates a session configuration file

Retrieves results from disconnected sessions

Close Windows PowerShell sessions

Disconnects you from the current session
$s = New-PSSession -ComputerName (Get-Content Servers.txt) -Credential Domain01\Admin01

New-PSSessionConfigurationFile -Path .\NoLanguage.pssc -LanguageMode NoLanguage

Receive-PSSession -ComputerName Server01 -Name ITTask

$r = Get-PSSession -ComputerName Serv* $r | Remove-PSSession

Import Export File Cmdlets

CmdletDescriptionExample
Export-Csv

Import-Csv

Export-Clixml

Import-Clixml
Convert objects into multiple CSV strings and export the strings to a CSV document

Build table-like custom objects using all the items in a CSV file

Creates an XML-based representation of objects and stores it in a file

Import XML to Object

Get-Process | Export-Csv -Path .\Processes.csv -NoTypeInformation

$Credential | Export-Clixml ./cred2.xm

Module Cmdlets

CmdletDescriptionExample
Import-Module

Get-Module

Install-Module

New-Module
Import modules to your current session

List the modules imported in the current session

Downloads module from a repository, and installs them

Creates a new dynamic module that exists in memory
Import-Module -Name PSDiagnostics

Get-Module -ListAvailable

Install-Module -Name PowerShellGet

Format Cmdlets

CmdletDescriptionExample

Format-List

Format-Table

Format-Hex

Format-Wide

Format-Custom
Format the output as a properties list

format the output as a table

Displays an input as a hexadecimal

Format objects as wide tables where only one property

Use a customized view in order to format the output
Get-Process | Format-List -Property name, basepriority

Get-Process | Format-Table -GroupBy BasePriority -Wrap

Format-Hex -Path .\File.t7f

Get-ChildItem | Format-Wide -Column 3

Get-Process | Export-Csv -Path .\Processes.csv -NoTypeInformation

Get-Date | Format-Custom DayOfWeek,{ $_ / $null } -DisplayError

More PowerShell articles:

How to download files from the Web using PowerShell

Code Signing with PowerShell

How to check Windows Features installed using PowerShell

How to restore VM Snapshot remotely using PowerShell

Leave a Comment