Skip to content

Instantly share code, notes, and snippets.

@phyoewaipaing
Last active March 26, 2024 05:44
Show Gist options
  • Save phyoewaipaing/289c9cc639d1719f4c41388b3676af25 to your computer and use it in GitHub Desktop.
Save phyoewaipaing/289c9cc639d1719f4c41388b3676af25 to your computer and use it in GitHub Desktop.
Function to add the winget executable path to registry
function Add-WinGetPath-Registry {
$WinGetPath = (Get-ChildItem -Path $env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller*_x64*\winget.exe).DirectoryName
$oldPath = (Get-Item -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment').GetValue('path',$null,'DoNotExpandEnvironmentNames')
If (-Not(($oldPath -split ';') -contains $WinGetPath))
{
$newPath += $oldPath + ';' + $WinGetPath
"Winget path $WinGetPath added to registry"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
}
else
{
"Winget path already exists in registry."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment