PowerShell Commands
Windows PowerShell cmdlets. They pass objects down the pipeline (|), so you can filter, sort, and pick properties.
Practice these in Terminal Practice
Moving around
-
Get-Location - Shows the current folder (aliases: pwd, gl).
-
Set-Location - Changes the current folder (aliases: cd, sl, chdir).
-
Get-ChildItem - Lists the files and folders in a location (aliases: ls, dir, gci).
-
Test-Path - Checks whether a file or folder exists (True or False).
Files
-
Get-Content - Shows the lines of a file (aliases: cat, type, gc).
-
Set-Content - Replaces the contents of a file.
-
Add-Content - Adds lines to the end of a file.
-
Out-File - Saves the output of a pipeline to a file (like > ).
-
New-Item - Creates a new file or folder (alias: ni). Use -ItemType Directory for folders.
-
mkdir - Creates a folder (shortcut for New-Item -ItemType Directory; alias: md).
-
Copy-Item - Copies a file or folder (aliases: copy, cp, cpi).
-
Move-Item - Moves a file or folder (aliases: move, mv, mi).
-
Rename-Item - Renames a file or folder (aliases: ren, rni).
-
Remove-Item - Deletes files or folders (aliases: rm, del, erase, rd, rmdir, ri).
-
Select-String - Finds text in files or piped lines, like grep (alias: sls).
The pipeline
-
Where-Object - Keeps only the objects that match, e.g. Where-Object { $_.Status -eq 'Running' } (aliases: where, ?).
-
Sort-Object - Sorts objects by one or more properties (alias: sort). Add -Descending for biggest first.
-
Select-Object - Picks properties (Select-Object Name, Status) or items (-First 5, -Last 3) (alias: select).
-
Measure-Object - Counts objects, and can -Sum, -Average, -Maximum, -Minimum a property (alias: measure).
-
Group-Object - Groups objects by a property and counts each group (alias: group).
-
ForEach-Object - Runs a script block for each object, e.g. ForEach-Object { $_.Name } (aliases: foreach, %).
-
Format-Table - Shows objects as a table, optionally with chosen properties (alias: ft).
-
Format-List - Shows every property of each object as "Name : Value" lines (alias: fl).
Services and processes
-
Get-Service - Lists services and whether they are running (alias: gsv).
-
Start-Service - Starts one or more stopped services (alias: sasv).
-
Stop-Service - Stops one or more running services (alias: spsv).
-
Restart-Service - Stops and then starts a service.
-
Set-Service - Changes a service, e.g. -StartupType Automatic|Manual|Disabled.
-
Get-Process - Lists running programs with their memory and CPU use (aliases: ps, gps).
-
Stop-Process - Ends a running program by -Name or -Id (aliases: kill, spps).
Network
-
Test-Connection - The PowerShell version of ping. -Count sets how many; -Quiet just says True/False.
-
Test-NetConnection - Checks whether a TCP port is open on another computer, e.g. -Port 443.
-
Resolve-DnsName - The PowerShell version of nslookup.
-
Get-NetIPAddress - Lists this computer's IP addresses.
-
ipconfig - Shows the IP address, subnet mask, and gateway. ipconfig /all shows more.
-
ping - Checks whether another computer answers. ping -n 2 <host> sends 2 pings.
-
nslookup - Asks the DNS server for the IP address of a name.
Users
-
Get-LocalUser - Lists the local user accounts on this machine.
-
Enable-LocalUser - Enables a local user account.
-
Disable-LocalUser - Disables a local user account.
-
whoami - Shows who you are logged in as (computer\user).
The system
-
Get-EventLog - Reads the System or Application event log, e.g. -LogName System -EntryType Error -Newest 5.
-
Get-Volume - Shows each disk volume with its size and free space.
-
Get-Date - Shows the current date and time.
-
hostname - Shows this computer's name.
Help and the console
-
Get-Help - Explains a command (aliases: help, man). Try Get-Help Get-Service, or 'help all'.
-
Get-Command - Lists the commands you can use (alias: gcm). Try Get-Command *-Service.
-
Get-History - Lists the commands you have typed (aliases: h, history).
-
Write-Output - Sends text or objects down the pipeline (aliases: echo, write).
-
Clear-Host - Clears the screen (aliases: cls, clear).
From localhostmonkey.com/learn/cheat-sheets/powershell/