Listen to this Post

PowerShell is a powerful scripting language and command-line shell designed for task automation and configuration management. Below is a comprehensive cheat sheet covering essential commands, security policies, and CLI operations.
Basic PowerShell Commands
– `Get-Command` – Lists all available commands.
– `Get-Help` – Displays help for a cmdlet (e.g., Get-Help Get-Process).
– `Get-Process` – Lists all running processes.
– `Stop-Process -Name “ProcessName” -Force` – Terminates a process forcefully.
– `Get-Service` – Displays all services.
– `Start-Service -Name “ServiceName”` – Starts a service.
– `Stop-Service -Name “ServiceName”` – Stops a service.
File & Directory Operations
– `Get-ChildItem` – Lists files and directories (equivalent to `ls` or dir).
– `Copy-Item “Source” “Destination”` – Copies files/folders.
– `Remove-Item “Path”` – Deletes a file or directory.
– `New-Item -ItemType File -Name “File.txt”` – Creates a new file.
– `Set-Location “Path”` – Changes the current directory (cd equivalent).
System & Security Management
– `Get-ExecutionPolicy` – Checks the current script execution policy.
– `Set-ExecutionPolicy RemoteSigned` – Allows local scripts but requires signed remote scripts.
– `Get-NetFirewallRule` – Lists all firewall rules.
– `Enable-NetFirewallRule -DisplayName “RuleName”` – Enables a firewall rule.
– `Disable-NetFirewallRule -DisplayName “RuleName”` – Disables a firewall rule.
Networking & Remote Management
– `Test-NetConnection -ComputerName “Host” -Port 80` – Checks connectivity to a host on a specific port.
– `Invoke-WebRequest -Uri “URL”` – Downloads content from a URL (wget equivalent).
– `Enter-PSSession -ComputerName “RemotePC”` – Starts a remote PowerShell session.
– `Get-NetIPConfiguration` – Displays network configuration (IP, DNS, etc.).
Scripting & Automation
– `ForEach-Object { $_ }` – Iterates over objects in a pipeline.
– `If (condition) { action } Else { alternative }` – Basic conditional logic.
– `$Variable = “Value”` – Declares a variable.
– `Write-Output “Message”` – Prints output to the console.
You Should Know:
- Execution Policies: PowerShell restricts script execution by default. Use `Set-ExecutionPolicy` to adjust security levels.
- Remote Scripts: Always verify scripts from untrusted sources before execution.
- Logging: Enable PowerShell logging (
Start-Transcript) for auditing. - Modules: Use `Install-Module -Name “ModuleName”` to extend functionality.
What Undercode Say
PowerShell is indispensable for Windows administrators and security professionals. Mastering it enhances automation, security hardening, and system diagnostics. Key takeaways:
– Use `Get-Member` to explore object properties.
– Secure scripts with `Sign-Script` to prevent tampering.
– Leverage `Where-Object` for filtering data.
– Automate repetitive tasks with scheduled jobs (Register-ScheduledJob).
– For Linux cross-compatibility, check PowerShell Core (pwsh).
Expected Output:
PS C:> Get-Process | Where-Object { $_.CPU -gt 50 }
PS C:> Get-Service | Export-CSV "Services.csv"
PS C:> Invoke-WebRequest "https://example.com/file.exe" -OutFile "C:\Downloads\file.exe"
For advanced scripting, refer to Microsoft’s PowerShell Documentation.
References:
Reported By: Https: – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


