powershell Commands

Core

Get-Help

Displays information about PowerShell commands and concepts.

Get-Help

Examples:
Get help for the Get-Process command
Get-Help Get-Process
Show detailed help for Get-Process
Get-Help Get-Process -Detailed
Show only examples for Get-Process
Get-Help Get-Process -Examples
Get-Command

Gets all commands that are installed on the computer, including cmdlets, aliases, functions, and workflows.

Get-Command

Examples:
Get all commands
Get-Command
Get all commands with the verb 'Get' and noun 'Service'
Get-Command -Verb Get -Noun Service
Get all commands in the Microsoft.PowerShell.Management module
Get-Command -Module Microsoft.PowerShell.Management

Process Management

Get-Process

Gets the processes that are running on the local computer.

Get-Process

Examples:
Get all running processes
Get-Process
Get a specific process by name
Get-Process -Name 'powershell'
Get a process by ID and format the output as a list
Get-Process -Id 1234 | Format-List *
Stop-Process

Stops one or more running processes.

Stop-Process

Examples:
Stop a process by name
Stop-Process -Name 'Notepad'
Stop a process by ID without a prompt
Stop-Process -Id 1234 -Force

System Management

Get-Service

Gets the services on a local or remote computer.

Get-Service

Examples:
Get all services
Get-Service
Get services with names starting with 'win'
Get-Service -Name win*
Get a specific service and pipe it to Format-List
Get-Service -Name WinRM | Format-List *
Get-EventLog

Gets events in the classic event logs of a local or remote computer.

Get-EventLog

Examples:
Get the 10 newest entries from the System log
Get-EventLog -LogName System -Newest 10
Get all Error entries from the Application log
Get-EventLog -LogName Application -EntryType Error
Get-WmiObject

Gets instances of Windows Management Instrumentation (WMI) classes. (Legacy, use Get-CimInstance in newer PowerShell versions).

Get-WmiObject

Examples:
Get BIOS information
Get-WmiObject -Class Win32_BIOS
Get operating system information from a remote computer
Get-WmiObject -Class Win32_OperatingSystem -ComputerName Server01
Get-CimInstance

Gets the CIM instances of a class from a CIM server. (Modern replacement for Get-WmiObject).

Get-CimInstance

Examples:
Get BIOS information
Get-CimInstance -ClassName Win32_BIOS
Get operating system information
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property *

Security

Set-ExecutionPolicy

Changes the user preference for the PowerShell execution policy.

Set-ExecutionPolicy

Examples:
Set the execution policy to RemoteSigned for the current user
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Get the current execution policy
Get-ExecutionPolicy -List

File System

Get-ChildItem

Gets the items and child items in one or more specified locations.

Get-ChildItem

Examples:
List items in the current directory
Get-ChildItem
Recursively list all items in a directory
Get-ChildItem -Path C:\Users\ -Recurse
List only files in the current directory, including hidden files
Get-ChildItem -File -Force
Get-Content

Gets the content of the item at the specified location.

Get-Content

Examples:
Display the content of a file
Get-Content -Path .\MyFile.txt
Get the first 10 lines of a file
Get-Content .\MyFile.txt -TotalCount 10
Get the last 5 lines and keep watching for new lines
Get-Content .\MyLog.log -Tail 5 -Wait
Set-Content

Writes new content or replaces the content in a file.

Set-Content

Examples:
Create a new file with content (overwrites if exists)
Set-Content -Path .\NewFile.txt -Value 'Hello, World!'
Clear the content of a file
Set-Content -Path .\OldFile.txt -Value ''
Add-Content

Adds content to a specified item, such as a file.

Add-Content

Examples:
Append a line of text to a file
Add-Content -Path .\Log.txt -Value 'New log entry'
Test-Path

Determines whether all elements of a path exist.

Test-Path

Examples:
Check if a file exists
Test-Path -Path 'C:\Windows\System32\kernel32.dll'
Check if a path is a directory
Test-Path -Path 'C:\Windows' -PathType Container

Networking

Invoke-WebRequest

Gets content from a web page on the Internet.

Invoke-WebRequest

Examples:
Get a web page
Invoke-WebRequest -Uri 'https://www.google.com'
Download a file
Invoke-WebRequest -Uri 'https://example.com/file.zip' -OutFile '.\file.zip'
Make a POST request with a JSON body
$body = @{ key = 'value' } | ConvertTo-Json; Invoke-WebRequest -Uri 'https://api.example.com/items' -Method POST -Body $body -ContentType 'application/json'
Invoke-RestMethod

Sends an HTTP or HTTPS request to a RESTful web service and parses the response.

Invoke-RestMethod

Examples:
Get data from a public REST API
Invoke-RestMethod -Uri 'https://jsonplaceholder.typicode.com/todos/1'
Make a POST request with a JSON body
$body = @{ title = 'foo'; body = 'bar'; userId = 1 } | ConvertTo-Json; Invoke-RestMethod -Uri 'https://jsonplaceholder.typicode.com/posts' -Method POST -Body $body -ContentType 'application/json'