Killing the internet one fake blog post at a time.

List of PowerShell CmdLets.

Written in

by

PowerShell cmdlets, are commands in PowerShell that perform specific tasks. Here is a list of some commonly used PowerShell cmdlets and how to use them:

  1. Get-Process – Displays information about running processes on the system. Example: Get-Process
  2. Get-Service – Displays information about running services on the system. Example: Get-Service
  3. Get-HotFix – Displays information about installed hotfixes on the system. Example: Get-HotFix
  4. Get-ChildItem – Displays a list of files and directories in a specified location. Example: Get-ChildItem C:\
  5. Get-Content – Displays the contents of a file. Example: Get-Content C:\example.txt
  6. Set-Content – Replaces the contents of a file with new content. Example: Set-Content C:\example.txt "New Content"
  7. New-Item – Creates a new file or directory. Example: New-Item C:\example.txt
  8. Remove-Item – Deletes a file or directory. Example: Remove-Item C:\example.txt
  9. Rename-Item – Renames a file or directory. Example: Rename-Item C:\example.txt NewName.txt
  10. Move-Item – Moves a file or directory to a new location. Example: Move-Item C:\example.txt D:\
  11. Copy-Item – Copies a file or directory to a new location. Example: Copy-Item C:\example.txt D:\
  12. Test-Path – Checks if a file or directory exists. Example: Test-Path C:\example.txt
  13. Get-ItemProperty – Displays the properties of a file or directory. Example: Get-ItemProperty C:\example.txt
  14. Get-Date – Displays the current date and time. Example: Get-Date
  15. Get-Random – Generates a random number. Example: Get-Random
  16. Write-Host – Writes text to the console. Example: Write-Host "Hello, World!"
  17. Read-Host – Prompts the user for input. Example: Read-Host "What is your name?"
  18. Out-File – Sends output to a file. Example: Get-Process | Out-File C:\example.txt
  19. Format-List – Displays output in a formatted list. Example: Get-Process | Format-List Name, Id, CPU
  20. Format-Table – Displays output in a formatted table. Example: Get-Process | Format-Table Name, Id, CPU
  21. Sort-Object – Sorts output by a specified property. Example: Get-Process | Sort-Object CPU -Descending
  22. Select-Object – Selects specific properties to display. Example: Get-Process | Select-Object Name, Id, CPU
  23. Where-Object – Filters output based on a specified condition. Example: Get-Process | Where-Object { $_.CPU -gt 50 }
  24. ForEach-Object – Performs a specified operation on each item in a collection. Example: Get-ChildItem | ForEach-Object { Write-Host $_.Name }
  25. If – Executes a block of code if a condition is true. Example: if ($a -lt $b) { Write-Host "a is less than b" }
  26. Else – Specifies a block of code to execute if the preceding If condition is false. Example: If ($a -gt 10) { Write-Host "a is greater than 10" } Else { Write-Host "a is less than or equal to 10" }
  1. Switch – Selects a block of code to execute based on a specified value. Example: switch ($a) { 1 { Write-Host "a is 1" }; 2 { Write-Host "a is 2" }; default { Write-Host "a is something else" } }
  2. For – Executes a block of code a specified number of times. Example: for ($i = 1; $i -le 10; $i++) { Write-Host $i }
  3. While – Executes a block of code as long as a condition is true. Example: while ($a -lt 10) { $a++ }
  4. Do-While – Executes a block of code at least once and then continues to execute as long as a condition is true. Example: do { Write-Host $a; $a++ } while ($a -lt 10)
  5. Break – Exits a loop. Example: for ($i = 1; $i -le 10; $i++) { if ($i -eq 5) { Break } Write-Host $i }
  6. Continue – Skips to the next iteration of a loop. Example: for ($i = 1; $i -le 10; $i++) { if ($i -eq 5) { Continue } Write-Host $i }
  7. Try-Catch – Handles errors in a block of code. Example: try { Get-ChildItem -Path "C:\example.txt" } catch { Write-Host "An error occurred" }
  8. Test-NetConnection – Checks the status of a network connection. Example: Test-NetConnection -ComputerName "google.com" -Port 80
  9. New-NetFirewallRule – Creates a new firewall rule. Example: New-NetFirewallRule -DisplayName "My Firewall Rule" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 80
  10. Enable-NetFirewallRule – Enables a firewall rule. Example: Enable-NetFirewallRule -DisplayName "My Firewall Rule"
  11. Disable-NetFirewallRule – Disables a firewall rule. Example: Disable-NetFirewallRule -DisplayName "My Firewall Rule"
  12. Get-NetAdapter – Displays information about network adapters. Example: Get-NetAdapter
  13. Set-NetAdapter – Configures network adapters. Example: Set-NetAdapter -Name "Ethernet" -Dhcp Enabled
  14. Get-NetIPAddress – Displays information about IP addresses. Example: Get-NetIPAddress
  15. Set-NetIPAddress – Configures IP addresses. Example: Set-NetIPAddress -InterfaceIndex 1 -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1
  16. Get-NetRoute – Displays information about IP routing tables. Example: Get-NetRoute
  17. Set-NetRoute – Configures IP routing tables. Example: Set-NetRoute -DestinationPrefix 10.0.0.0/8 -InterfaceIndex 1 -NextHop 192.168.1.1
  18. Get-NetTCPConnection – Displays information about TCP connections. Example: Get-NetTCPConnection
  19. Stop-Process – Stops a running process. Example: Stop-Process -Name notepad

This is just a small selection of the many cmdlets available in PowerShell. To learn more about cmdlets and their usage, you can refer to the official Microsoft documentation.

Tags