Command | Description | Example |
---|---|---|
Get-Location |
Print working directory | Get-Location |
Get-ChildItem |
List directory contents | Get-ChildItem |
Set-Location [path] |
Change directory | Set-Location -Path C:\Users |
Copy-Item [source] [destination] |
Copy files or directories | Copy-Item -Path file.txt -Destination C:\Users |
Move-Item [source] [destination] |
Move or rename files or directories | Move-Item -Path oldname.txt -Destination newname.txt |
Remove-Item [file] |
Remove files | Remove-Item -Path file.txt |
New-Item -ItemType File [file] |
Create a new empty file | New-Item -ItemType File -Name newfile.txt |
New-Item -ItemType Directory [directory] |
Create new directory | New-Item -ItemType Directory -Name newdirectory |
Remove-Item [directory] |
Remove empty directory | Remove-Item -Path olddirectory |
Command | Description | Example |
---|---|---|
Get-Content [file] |
Display file content | Get-Content -Path file.txt |
Set-Content [file] -Value [content] |
Write content to a file | Set-Content -Path file.txt -Value "Hello, World!" |
Add-Content [file] -Value [content] |
Append content to a file | Add-Content -Path file.txt -Value "Hello, World!" |
Command | Description | Example |
---|---|---|
Get-Acl [file] |
Get file permissions | Get-Acl -Path file.txt |
Set-Acl [file] -AclObject [acl] |
Set file permissions | $acl = Get-Acl -Path file.txt; Set-Acl -Path file.txt -AclObject $acl |
Command | Description | Example |
---|---|---|
Get-ChildItem [directory] -Filter [filename] |
Find files by name | Get-ChildItem -Path C:\Users -Filter "*.txt" |
Select-String -Path [file] -Pattern [pattern] |
Search for a pattern within files | Select-String -Path file.txt -Pattern "search term" |
Get-Command [command] |
Show the path of a command | Get-Command -Name Get-Process |
Command | Description | Example |
---|---|---|
Get-ComputerInfo |
Show all system information | Get-ComputerInfo |
Get-Process |
Display running processes | Get-Process |
Get-Service |
Display running services | Get-Service |
Get-HotFix |
Show installed updates | Get-HotFix |
Command | Description | Example |
---|---|---|
Test-Connection [host] |
Send ICMP ECHO_REQUEST to network hosts | Test-Connection -ComputerName google.com |
Get-NetIPAddress |
Show IP addresses and network interfaces | Get-NetIPAddress |
Invoke-WebRequest [url] |
Download files from the web | Invoke-WebRequest -Uri http://example.com/file.zip -OutFile file.zip |
Enter-PSSession -ComputerName [host] |
Connect to a remote host via PowerShell Remoting | Enter-PSSession -ComputerName remotehost |
Command | Description | Example |
---|---|---|
Get-Package |
List installed packages | Get-Package |
Install-Package [package] |
Install a package | Install-Package -Name 7zip |
Uninstall-Package [package] |
Uninstall a package | Uninstall-Package -Name 7zip |
Command | Description | Example |
---|---|---|
Get-Volume |
List disk volumes | Get-Volume |
Format-Volume -DriveLetter [letter] |
Format a volume | Format-Volume -DriveLetter D |
Check-FileSystem -DriveLetter [letter] |
Check and repair a file system | Check-FileSystem -DriveLetter C |
Command | Description | Example |
---|---|---|
.\[script].ps1 |
Run a PowerShell script | .\script.ps1 |
Start-Job -ScriptBlock { [command] } |
Run a command as a background job | Start-Job -ScriptBlock { Get-Process } |
Get-Job |
List background jobs | Get-Job |
Stop-Job -Id [id] |
Stop a background job | Stop-Job -Id 1 |
Command | Description | Example |
---|---|---|
Get-ChildItem Env: |
List all environment variables | Get-ChildItem Env: |
$Env:[VARIABLE] |
Print value of a variable | $Env:PATH |
$Env:[VARIABLE] = "[value]" |
Set an environment variable | $Env:PATH = "C:\Program Files" |
Command | Description | Example |
---|---|---|
Get-LocalUser |
List local users | Get-LocalUser |
New-LocalUser -Name [user] |
Add a new local user | New-LocalUser -Name newuser |
Remove-LocalUser -Name [user] |
Delete a local user | Remove-LocalUser -Name olduser |
Get-LocalGroup |
List local groups | Get-LocalGroup |
Add-LocalGroupMember -Group [group] -Member [user] |
Add user to group | Add-LocalGroupMember -Group "Administrators" -Member newuser |
Command | Description | Example |
---|---|---|
Compress-Archive -Path [path] -DestinationPath [archive.zip] |
Create a zip archive | Compress-Archive -Path C:\Users\Documents -DestinationPath archive.zip |
Expand-Archive -Path [archive.zip] -DestinationPath [path] |
Extract a zip archive | Expand-Archive -Path archive.zip -DestinationPath C:\Users\Documents |
Command | Description | Example |
---|---|---|
New-Alias [alias_name] [command] |
Create a command alias | New-Alias ll Get-ChildItem |
Get-History |
Show command history | Get-History |
Invoke-History -Id [id] |
Run the last command again | Invoke-History -Id 1 |
Get-Help [command] |
Show the manual for a command | Get-Help Get-ChildItem |
Write-Output [text] |
Print text to the terminal | Write-Output "Hello, World!" |
Get-Date |
Show current date and time | Get-Date |