-
-
Save phyoewaipaing/289c9cc639d1719f4c41388b3676af25 to your computer and use it in GitHub Desktop.
Function to add the winget executable path to registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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