PowerShell
PowerShell blog sharing useful tips and tricks to boost efficiency, published by Peter Whyte, an experienced Microsoft SQL Server Database Administrator.
-
Try Catch in PowerShell: Why catch Does Not Run
A PowerShell catch block only runs on terminating errors. Use -ErrorAction Stop to catch cmdlet errors, catch specific exception types, and add finally.
-
List Installed Windows Updates with Get-HotFix
List installed Windows updates with Get-HotFix, newest first, check whether one KB is installed, filter by date, and why Get-HotFix shows fewer updates than Update history.
-
Write-Host vs Write-Output in PowerShell
Write-Host prints to the screen and cannot be captured in a variable or pipeline; Write-Output sends objects down the pipeline. See the difference and which one to use.
-
Fix “A positional parameter cannot be found that accepts argument” in PowerShell
PowerShell says a positional parameter cannot be found that accepts argument. Read which argument it names, then check for commands joined on one line, a path with a space and no quotes, a parameter name without its dash, or a list without commas.
-
Time a Command in PowerShell with Measure-Command
Time a command in PowerShell with Measure-Command, get just the seconds, average several runs, see the output it hides, and why Seconds is not the whole time.
-
Unblock a Downloaded File in PowerShell (Unblock-File)
Remove the mark of the web from downloaded scripts and files with Unblock-File, see the Zone.Identifier stream with Get-Item -Stream, and unblock a whole folder.
-
Get Your IP Address in PowerShell
Get your IP address in PowerShell with Get-NetIPAddress, find the one adapter that matters with the default route, see gateway and DNS with Get-NetIPConfiguration, and look up your public IP.
-
PowerShell curl: Why -Uri and -OutFile Stopped Working
In Windows PowerShell 5.1 curl is an alias for Invoke-WebRequest. In PowerShell 7 it is not, it runs curl.exe, and the old flags either error or sit there asking for a password. Here is what to run in each.
-
PSReadLine Predictive IntelliSense: Show Suggestions as a List
Turn on PSReadLine predictive IntelliSense in PowerShell 7 with suggestions from your history shown as a list, keep it in your profile, and what Windows PowerShell 5.1 needs.