docs

a slatepencil documentail site

View on GitHub

POWER SHELL

PowerShell is an interactive Command-Line Interface (CLI) and automation engine designed by Microsoft to help design system configurations and automate administrative tasks.

Command name Alias Description
Set-Location cd, chdir, sl Sets the current working location to a specified location.
Get-Content cat, gc, type Gets the content of the item at the specified location.
Add-Content ac Adds content to the specified items, such as adding words to a file.
Set-Content sc Writes or replaces the content in an item with new content.
Copy-Item copy, cp, cpi Copies an item from one location to another.
Remove-Item del, erase, rd, ri, rm, rmdir Deletes the specified items.
Move-Item mi, move, mv Moves an item from one location to another.
Set-Item si Changes the value of an item to the value specified in the command.
New-Item ni Creates a new item.
Start-Job sajb Starts a Windows PowerShell background job.
Compare-Object compare, dif Compares two sets of objects.
Group-Object group Groups objects that contain the same value for specified properties.
Invoke-WebRequest curl, iwr, wget Gets content from a web page on the Internet.
Measure-Object measure Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files …
Resolve-Path rvpa Resolves the wildcard characters in a path, and displays the path contents.
Resume-Job rujb Restarts a suspended job
Set-Variable set, sv Sets the value of a variable. Creates the variable if one with the requested name does not exist.
Show-Command shcm Creates Windows PowerShell commands in a graphical command window.
Sort-Object sort Sorts objects by property values.
Start-Service sasv Starts one or more stopped services.
Start-Process saps, start Starts one or more processes on the local computer.
Suspend-Job sujb Temporarily stops workflow jobs.
Wait-Job wjb Suppresses the command prompt until one or all of the Windows PowerShell background jobs running in the session are …
Where-Object ?, where Selects objects from a collection based on their property values.
Write-Output echo, write Sends the specified objects to the next command in the pipeline. If the command is the last command in the pipeline,…
# View the PATH environment variable
$env:PATH
# Set an environment variable
$env:APP_PORT = 8000

# Search for a specific pattern in a file
Select-String <pattern> <file>

# Search for a pattern in a file's content
Get-Content <file> | Select-String <pattern>

Get-NetIPAddress # Display IP addresses.
Set-DnsClientServerAddress -InterfaceIndex <index> -ServerAddresses <DNS_server> # Set DNS server addresses.
# Test network connection to a specific host
Test-NetConnection <hostname>

# Test network connection to a specific host and port
Test-NetConnection <hostname> -Port <port>

Get-Service # List all services.
Start-Service <service_name>  # Start a specific service.
Stop-Service <service_name>  # Stop a specific service.
Restart-Service <service_name>  # Restart a specific service.

Get-Process  # List running processes.
Stop-Process <processID>  # Stop a process with a specific ID.
Start-Process <program>  # Start a new process.

Get-LocalUser # List local users.
New-LocalUser <username> # Create a new local user.
Add-LocalGroupMember -Group <group_name> -Member <username> # Add a user to a local group.

# system information
Get-WmiObject -Class Win32_ComputerSystem # Get information about the computer system.
Get-WmiObject -Class Win32_Processor # Get information about the processor.
Get-WmiObject -Class Win32_LogicalDisk # Get information about disk drives.

# event logs
Get-EventLog -LogName <log_name> # Retrieve events from a specific event log.
Clear-EventLog -LogName <log_name> # Clear events from a specific event log.

# windows features
Get-WindowsFeature # List installed Windows features.
Install-WindowsFeature <feature_name> # Install a Windows feature.
Uninstall-WindowsFeature <feature_name> # Uninstall a Windows feature.

# remote management
Enter-PSSession -ComputerName <computer_name> # Enter a remote PowerShell session.
Invoke-Command -ComputerName <computer_name> -ScriptBlock {<command>} # Run a command on a remote computer.