This PowerShell Cheat Sheet contains scripts or notes I find useful in the field as a DBA.

I hope you enjoy and find my PowerShell ‘cheats’ below useful.

General Admin
# Restart Services Multiple Hosts
# Send an Email
# For Loops
# Check PowerShell Version
# Disk Management

Files & Folders
# Copy Files to a Remote Host
# Delete Files & Folders
# Compress & Password Protect Files
# Count Rows in .CSV Files
# Map a Network Drive

Local Host Configuration
# Enable/Disable Windows Firewall
# Create a Windows Firewall Rule
# Set IP Address
# Create a Self-Signed Certificate

Restart Services Multiple Servers

Blog Post: https://peter-whyte.com/powershell-restart-services-multiple-hosts/

# Restart service on multiple hosts
$parameters = @{
  ComputerName = 
    "Hostname1",
    "Hostname2",
    "Hostname3"
  ScriptBlock = { Restart-Service *SQLSERVERAGENT* }
}
Invoke-Command @parameters

Delete Files & Folders





Enable/Disable Windows Firewall





Create Self-Signed Certificate