r/PowerShell • u/mdowst • Dec 11 '25
PowerShell Script to Detect Code Impacted by the Invoke-WebRequest Breaking Change
The recent breaking change to Invoke-WebRequest in Windows PowerShell 5.1 has the potential to affect a lot of automation, especially in older environments. To make it easier to assess the impact, I published a script called Search-CmdletParameterUsage.ps1.
This tool recursively scans your scripts and modules for any cmdlet + parameter usage. While I built it to identify places where Invoke-WebRequest is not using -UseBasicParsing, it works generically for any cmdlet you're concerned about.
If you maintain large codebases or inherited automation, this can save a ton of manual review.
Script: https://gist.github.com/mdowst/9d00ff37ea79dcbfb98e6de580cbedbe
KB on the breaking change: https://support.microsoft.com/en-us/topic/powershell-5-1-preventing-script-execution-from-web-content-7cb95559-655e-43fd-a8bd-ceef2406b705
Happy scripting! And good luck hunting down those IWR calls.
12
u/g3n3 Dec 11 '25
Probably need to add searching iex recursively and odd variables defined as script blocks too recursively.
10
u/lan-shark Dec 11 '25
Also, folks, remember that you can add
UseBasicParsingto your default parameters to mitigate this issue without directly changing scriptsAnd hopefully this goes without saying, but don't apply the update until after you've mitigated any issues
4
u/surfingoldelephant Dec 11 '25 edited Dec 25 '25
Nice idea.
The function works pretty well. Just a few minor issues/edge cases:
-Parameter:Argumentisn't correctly reported.}.$assignments[-1]breaks if the same name is used for multiple splatting variables.For #2, parsing
@{ Foo = 1 }yields1 }. But I wouldn't use regex at all for this. You can get the value straight from theHashtableAst.For #3, the following breaks (
$falseis reported for both below):You need to look for the closest initialization of the variable preceding the command call instead.
For #4, you'd need to look at
New-Variableusage, expressions that modify the variable's value, etc. Probably all overkill though.For #1, you're assuming that if there's a
CommandParameterAstafter the currentCommandParameterAst(or if there are no elements remaining), the current element must be a$trueswitch. But that doesn't account for colon-delimited named arguments. All of these are incorrectly reported as$true:Look at the
Argumentproperty ofCommandParameterAst. If it's populated, you're dealing with a named argument (i.e., a parameter and argument). If it's$null, the next element may or may not the associated argument.Here's how I do it. This is an excerpt from a larger function that serves a similar purpose:
2
u/Certain-Community438 Dec 11 '25
Man am I glad we moved everything to pwsh "Core" Edition some time ago!
Outside of Intune scripts, where we don't use IWR; that could be risky.
2
u/icebreaker374 Dec 11 '25
So for automation scripts, I either HAVE to use basic parsing, OR run it with PS7, yes?
3
u/nkasco Dec 11 '25
My solution was just to open my repo in VS Code and do a search for it. Super simple
1
u/arpan3t Dec 11 '25
Curious why you only install SQLite on Windows? Also, leveraging
WinGet Install SQLite.SQLitewould be cleaner thanInvoke-WebRequestand regex parsing the HTML string for the download URL.You might test the speed of querying the browser history table for the URL patterns vs. converting every record in the table into objects and filtering from there. The database engine should be faster. As an example:
The SQL query ends up looking like this:
You also don't need to specify the
|separator in your SQLite command as that is the default. You can also just set the output mode to json and convert it to objects like so:The browser history code looks really similar. You can probably combine all the BrowserHistory.<browser>.ps1 into one and specify the browser with a parameter.
That's just what I noticed from a cursory glance at your code. It's a neat project!
NOTE: There's currently a hash mismatch on the SQLite WinGet package, a pull request was made yesterday to update the manifest so it should be fixed soon.
1
u/PutridLadder9192 Dec 14 '25
Do I need to update my Selenium powershell module
3
u/[deleted] Dec 11 '25
[removed] — view removed comment