Skip to content

Instantly share code, notes, and snippets.

@kilasuit
Last active April 4, 2025 03:26
Show Gist options
  • Save kilasuit/35456edca09dc825fa8510a6c89fb91d to your computer and use it in GitHub Desktop.
Save kilasuit/35456edca09dc825fa8510a6c89fb91d to your computer and use it in GitHub Desktop.
Some functions out of my setup script for installing Pwsh & PwshPreview via Microsoft update
function Install-PwshPreview {
$pwshRegPath = "HKLM:\SOFTWARE\Microsoft\PowerShellCore"
$previewPath = Join-Path -Path $pwshRegPath -ChildPath "InstalledVersions\39243d76-adaf-42b1-94fb-16ecf83237c8"
if (!(Test-Path -Path $previewPath)) {
$null = New-Item -Path $previewPath -ItemType Directory -Force
}
Set-ItemProperty -Path $pwshRegPath -Name UseMU -Value 1 -Type DWord
Set-ItemProperty -Path $previewPath -Name Install -Value 1 -Type DWord
}
function Install-Pwsh {
$pwshRegPath = "HKLM:\SOFTWARE\Microsoft\PowerShellCore"
$StablePath = Join-Path -Path $pwshRegPath -ChildPath "InstalledVersions\31ab5147-9a97-4452-8443-d9709f0516e1"
if (!(Test-Path -Path $StablePath)) {
$null = New-Item -Path $StablePath -ItemType Directory -Force
}
Set-ItemProperty -Path $pwshRegPath -Name UseMU -Value 1 -Type DWord
Set-ItemProperty -Path $StablePath -Name Install -Value 1 -Type DWord
}
Install-PwshPreview
Install-Pwsh
@kilasuit
Copy link
Author

kilasuit commented Apr 4, 2025

As of 2025/04/04 03:00am UTC +1 - I know this works as a way to ask Microsoft Update to install PowerShell or PowerShell Preview for you (as I've used it before)

I think adding

[System.Environment]::SetEnvironmentVariable('POWERSHELL_UPDATECHECK', 'LTS', 'Machine')

Prior to checking for updates should force the current 7.4.7 LTS install via this mechanism & not the current 7.5.0 stable release

@kilasuit
Copy link
Author

kilasuit commented Apr 4, 2025

Confirmed this works on a brand new Win 11 VM, so should be suitable on a Win Server 2025 vm too

image

@kilasuit
Copy link
Author

kilasuit commented Apr 4, 2025

However due to a bug in the update manifest that I reported you can see that v7.4.3 is also being downloaded unnecessarily.

image

@kilasuit
Copy link
Author

kilasuit commented Apr 4, 2025

This I think actually also needs the Receive updates for other Microsoft products when you update Windows setting to be on which I've previously done manually but I am lead to believe is done via

Set-ItemProperty 'HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings' -Name AllowMUUpdateService -Type DWord -Value 1

I reckon adding these below regkeys upfront (that the msi installer uses) would also ensure the installation goes as required

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment