r/PowerShell • u/RiverRatt • Sep 04 '26
Script Sharing PowerShell installer for .NET, Visual C++ and DirectX that bundles no binaries and resolves every download from Microsoft at run time
Rebuilt an old batch project of mine in PowerShell. It installs the .NET SDKs, the Visual C++ redistributables (current v14 plus the final 2005-2013 ones) and the June 2010 DirectX runtimes. Nothing is bundled and there are no hardcoded download URLs, so it locates everything on Microsoft's own hosts every run, then verifies each file before it executes.
Every discovery page and every payload URL goes through a check like this before anything gets fetched:
function Test-AllowedMicrosoftDiscoveryUri {
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(Mandatory = $true)]
[string]$Uri
)
try {
$parsedUri = [uri]$Uri
if (-not $parsedUri.IsAbsoluteUri) { return $false }
if ($parsedUri.Scheme -cne 'https') { return $false }
if ($parsedUri.Port -ne 443) { return $false }
if (-not [string]::IsNullOrEmpty($parsedUri.UserInfo)) { return $false }
return $parsedUri.DnsSafeHost -match $script:AllowedMicrosoftDiscoveryHostPattern
}
catch {
return $false
}
}Discovery pages and payloads use two separate host allowlists, so allowing a docs host never authorizes an executable coming from it. curl's reported effective URL gets checked the same way after redirects.
Verification depends on what Microsoft actually publishes. The .NET SDKs have a SHA-512 in the release metadata. The final 2005-2013 and DirectX packages never change, so those are pinned to SHA-256 values I checked by hand. The rolling v14 redistributable has no published hash at all, so that one gets Authenticode plus a version floor read out of the signed file. Nothing installs until the whole selected set has resolved, and a file that fails verification gets deleted even if you asked to keep the downloads.
Windows PowerShell 5.1 compatible, uses pwsh if it's in PATH. Source and usage notes:
11
u/JeremyLC Sep 04 '26
Is there a reason you're using curl.exe and not Invoke-WrbRequest even a .net http client? Not that either of those are easier, but they are more idiomatically PowerShell, and they don't depend on a third party executable.
Also, consider running only the installers themselves in an elevated context rather than the whole script. You leave less room for catastrophe.
Anyway, this does look very useful. I'll have to look again later when I'm in front of a real computer.
7
u/StartAutomating Sep 05 '26
This is overcomplicated, and, IMO, slop.
One does not need a 1000+ line "installer" script that bundles all of this with no options.
In fact, one might argue such a script should not exist: it should be leveraging existing installers, such as WinGet, Scoop, or Chocolatey.
Additionally, if your product/project is using 1000+ line installers to install itself, one would generally argue that you're doing it wrong.
I've seen this kinda slop before in AI generated installers and would very much like people to stop doing this. In the long run, it incentivizes bad behavior by normalizing "just irm | iex this magic 1000+ line installer that could should have been a package.
Given that the repo lists Claude as a co-author, I think it's quite clear this was not written by humans, or with much understanding about how to make the code shorter.
Please Do Not Do This
It wastes computing cycles and wastes our time trying to review it.
Unless You Absolutely Need to, Just Use Existing Installers. Please do not write your own.
2
u/BlackV Sep 05 '26
I feel like the 400
ifstatements should be aswitchinstead (just at first glance anyway)also not sure about the
returns2
u/warren_stupidity Sep 05 '26
you know winget does all this, right?