PowerShell
PowerShell blog sharing useful tips and tricks to boost efficiency, published by Peter Whyte, an experienced Microsoft SQL Server Database Administrator.
-
Call the Claude API From PowerShell
Send a prompt to Claude from PowerShell with Invoke-RestMethod: the API key in an environment variable, a JSON body built with ConvertTo-Json -Depth, UTF-8 in Windows PowerShell 5.1, reading the text from the reply, and handling errors.
-
Check an AI-Written PowerShell Script Before You Run It
Before you run a PowerShell script an AI wrote, check whether -WhatIf really works, read the param block, add Set-StrictMode, run PSScriptAnalyzer and use Get-Command to see what each command is.
-
Store API Keys Safely in PowerShell
Keep API keys out of your scripts with SecretManagement and SecretStore: Register-SecretVault, Set-Secret, Get-Secret -AsPlainText, checking your history for a pasted key, and the trade-off for scheduled tasks.
-
ConvertTo-Json Depth: Why Nested JSON Shows System.Collections.Hashtable
ConvertTo-Json only writes two levels by default, so nested data becomes System.Collections.Hashtable. Fix it with -Depth, why 5.1 gives no warning, API request bodies, the limit of 100, and the one-item array gotcha.
-
Kill a Process by Name or ID in PowerShell
Kill a process in PowerShell with Stop-Process, by name or by process ID, preview it with -WhatIf, stop whatever is holding a port, and why -Name notepad.exe finds nothing.
-
Search Your PowerShell Command History with Ctrl+R
Press Ctrl+R in PowerShell to search every command you have run before, keep pressing to cycle through matches, and Enter to run it. Plus F8, Get-History and where the PSReadLine history file lives.
-
Find Which Process Is Using a Port in PowerShell
Find which process is using a port on Windows with Get-NetTCPConnection and Get-Process, what it means when the answer is svchost or System, how to check UDP ports, and the netstat equivalent.
-
Top Processes by Memory in PowerShell (Get-Process)
List the ten processes using the most memory with Get-Process and Sort-Object, what WorkingSet64 and CPU mean, totals per program, and sorting by CPU instead.
-
Fix “UnicodeEncodeError: ‘charmap’ codec can’t encode character” in Python on Windows
Python on Windows stops with UnicodeEncodeError: 'charmap' codec can't encode character when it prints an arrow, a long dash or an emoji to a pipe or a file. Why it happens and the fixes: PYTHONIOENCODING, UTF-8 mode, sys.stdout.reconfigure, and why chcp 65001 does not help.