PowerShell
PowerShell blog sharing useful tips and tricks to boost efficiency, published by Peter Whyte, an experienced Microsoft SQL Server Database Administrator.
-
Check Free Disk Space in PowerShell (Get-Volume)
Show size, free space and percent free for every drive with Get-Volume, flag drives under 10 percent, check a remote server, and the Get-PSDrive alternative.
-
Copy PowerShell Output to the Clipboard (Set-Clipboard)
Copy PowerShell output to the clipboard with Set-Clipboard, keep the table layout with Out-String, copy the current folder path, append, read it back with Get-Clipboard, and the Windows PowerShell 5.1 file-copy trap.
-
Base64 Encode and Decode a String in PowerShell
Encode a string to Base64 and decode it back with [Convert] and [Text.Encoding], why the encoding must match, -EncodedCommand, and encoding a whole file.
-
Check if PowerShell Is Running as Administrator
Check if PowerShell is running as administrator with one line, stop a script early when it is not, use #Requires -RunAsAdministrator, and why an admin account is not enough.
-
Generate a Random Password in PowerShell
Generate random passwords in PowerShell from a character set without look-alike characters, and the cryptographically secure RandomNumberGenerator method in PowerShell 7.4 and later.
-
Find and Edit Your PowerShell Profile ($PROFILE)
Find your PowerShell profile with $PROFILE, create it safely if it does not exist, edit and reload it, the different paths for Windows PowerShell 5.1 and PowerShell 7, and why New-Item -Force can wipe it.
-
Find Files by Extension in PowerShell
Find every file of one type in a folder and its subfolders with Get-ChildItem -Filter, newest first, several extensions at once, and a count and size per extension.
-
Download a File with PowerShell (Invoke-WebRequest -OutFile)
Download a file with Invoke-WebRequest -OutFile and check it arrived, the 5.1 progress bar slowdown, saving to a folder in PowerShell 7, and checking the hash.
-
Get Folder Permissions in PowerShell with Get-Acl
Read folder permissions in PowerShell with Get-Acl, what the numbers 268435456 and -1610612736 mean, find permissions set by hand on subfolders, and why square brackets return nothing.