You are currently viewing Powershell Cheatsheet

Powershell Cheatsheet

PowerShell is a powerful task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. It allows administrators to perform complex tasks by simply writing scripts and provides a rich set of pre-built functions (cmdlets) that can be used to manage various services and systems.

We came up with a short yet comprehensive PowerShell cheat sheet covering various topics. We’ve included examples for most cmdlets to give you a better understanding of how they work. We will cover the following topics.

  1. Getting Help
  2. Running programs and finding files.
  3. Working with the filesystem.
  4. Working with registry keys.
  5. Working with services.

1. GETTING HELP
  • Get-Help: Display help for a cmdlet or concept.
codeGet-Help Get-Service
  • Get-Command: Display all available cmdlets.
codeGet-Command
  • Get-Member: Display the properties and methods of an object.
codeGet-Process | Get-Member

2. RUNNING PROGRAMS AND FINDING FILES
  • Start-Process: Start a program.
codeStart-Process notepad
  • Invoke-Item: Open a file.
codeInvoke-Item C:\Scripts\Script.ps1
  • Get-ChildItem: Display the files and subfolders in a folder.
codeGet-ChildItem C:\Scripts
  • Find-Item: Search for files and folders.
codeFind-Item -Path C:\Scripts -Filter *Script* -Recurse
  • Where-Object: Filter objects based on their properties.
codeGet-Process | Where-Object {$_.Handles -gt 1000}

3. WORKING WITH THE FILESYSTEM
  • Copy-Item: Copy files and folders.
codeCopy-Item C:\Scripts\Script.ps1 C:\Scripts\Backup\Script.ps1
  • Move-Item: Move files and folders.
codeMove-Item C:\Scripts\Script.ps1 C:\Scripts\Backup\Script.ps1
  • Remove-Item: Delete files and folders.
codeRemove-Item C:\Scripts\Script.ps1
  • Rename-Item: Rename a file or folder.
codeRename-Item C:\Scripts\Script.ps1 Script_Backup.ps1
  • New-Item: Create a new file or folder.
codeNew-Item C:\Scripts\Script.ps1 -ItemType File

4. WORKING WITH REGISTRY KEYS
  • Get-ItemProperty: Display the properties of a registry key.
codeGet-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion
  • Set-ItemProperty: Set the value of a registry key property.
codeSet-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate AutoUpdate 1
  • Remove-ItemProperty: Remove a property from a registry key.
codeRemove-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate AutoUpdate
  • New-ItemProperty: Create a new property for a registry key.
codeNew-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate AutoUpdate 1

5. WORKING WITH SERVICES
  • Get-Service: Display the services on a machine.
codeGet-Service
  • Start-Service: Start a service
Website | + posts

Leave a Reply