PowerShell Commands

PowerShell cmdlets and scripting reference.

File & Directory Operations

Get-ChildItem -Path C:\

List files and directories (ls)

Get-ChildItem -Recurse

List files recursively

Copy-Item -Path file.txt -Destination dest

Copy file

Move-Item -Path file.txt -Destination dest

Move file

Remove-Item -Path file.txt

Delete file

New-Item -Path file.txt -ItemType File

Create new file

New-Item -Path C:\dir -ItemType Directory

Create new directory

Test-Path -Path file.txt

Check if path exists

Get-Content -Path file.txt

Read file contents (cat)

Set-Content -Path file.txt -Value "text"

Write to file

Process Management

Get-Process

List all running processes (ps)

Get-Process -Name notepad

Get specific process by name

Stop-Process -Name notepad

Stop process by name

Stop-Process -Id 1234

Stop process by ID

Start-Process notepad.exe

Start a new process

Get-Process | Sort-Object CPU -Descending

List processes by CPU usage

Get-Process | Where-Object {$_.CPU -gt 100}

Filter processes by CPU

Services

Get-Service

List all services

Get-Service -Name wuauserv

Get specific service

Start-Service -Name wuauserv

Start a service

Stop-Service -Name wuauserv

Stop a service

Restart-Service -Name wuauserv

Restart a service

Set-Service -Name wuauserv -StartupType Automatic

Set service startup type

Get-Service | Where-Object {$_.Status -eq "Running"}

List running services

Network Commands

Test-Connection -ComputerName google.com

Ping a host

Test-NetConnection -ComputerName google.com -Port 443

Test TCP connection

Get-NetIPAddress

Show IP addresses

Get-NetIPConfiguration

Show network configuration (ipconfig)

Get-DnsClientCache

Display DNS cache

Clear-DnsClientCache

Clear DNS cache (ipconfig /flushdns)

Resolve-DnsName google.com

DNS lookup (nslookup)

Get-NetTCPConnection

Show TCP connections (netstat)

System Information

Get-ComputerInfo

Get detailed computer information

$PSVersionTable

Show PowerShell version

Get-Host

Get host information

Get-WmiObject Win32_OperatingSystem

Get OS information

Get-WmiObject Win32_ComputerSystem

Get computer system info

Get-WmiObject Win32_BIOS

Get BIOS information

Get-Hotfix

List installed Windows updates

Get-EventLog -LogName System -Newest 10

Get recent system events

User & Security

Get-LocalUser

List local user accounts

Get-LocalGroup

List local groups

New-LocalUser -Name "username"

Create new local user

Add-LocalGroupMember -Group "Administrators" -Member "user"

Add user to group

Get-ExecutionPolicy

Get current execution policy

Set-ExecutionPolicy RemoteSigned

Set execution policy

Get-Acl -Path C:\file.txt

Get file permissions

whoami /user

Show current user SID

Variables & Objects

$variable = "value"

Assign variable

Get-Variable

List all variables

$env:PATH

Access environment variable

[Environment]::SetEnvironmentVariable("VAR", "value", "User")

Set environment variable

Get-Member

Show object properties and methods

Get-Process | Get-Member

Show process object members

Measure-Object

Calculate numeric properties

Select-Object -Property Name, CPU

Select specific properties

Pipeline & Filtering

Get-Process | Where-Object {$_.CPU -gt 50}

Filter objects (where)

Get-Service | Sort-Object Status

Sort objects

Get-Process | Select-Object -First 5

Select first N objects

Get-ChildItem | Measure-Object -Property Length -Sum

Sum file sizes

Get-Process | Export-Csv processes.csv

Export to CSV

Import-Csv data.csv

Import from CSV

Get-Content file.txt | Select-String "pattern"

Search text (grep)

Get-Process | Out-GridView

Display in GUI grid view

Remote Management

Enter-PSSession -ComputerName server01

Start interactive remote session

Invoke-Command -ComputerName server01 -ScriptBlock {Get-Process}

Run command on remote computer

New-PSSession -ComputerName server01

Create persistent remote session

Get-PSSession

List active remote sessions

Remove-PSSession -Id 1

Close remote session

Enable-PSRemoting

Enable PowerShell remoting

Test-WSMan -ComputerName server01

Test WinRM connectivity

Registry & Configuration

Get-ItemProperty -Path "HKLM:\Software"

Read registry key

Set-ItemProperty -Path "HKLM:\Software" -Name "Key" -Value "Value"

Set registry value

New-Item -Path "HKLM:\Software\NewKey"

Create registry key

Remove-Item -Path "HKLM:\Software\Key"

Delete registry key

Get-PSDrive

List PowerShell drives (including registry)