PowerShell

Add winget to session path

# https://www.scriptinghouse.com/2024/03/resolving-winget-not-recognized-error-when-running-with-the-system-account.html
function Add-WinGetPath {
  $WinGetPath = (Get-ChildItem -Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller*_x64*\winget.exe").DirectoryName
  If (-Not(($Env:Path -split ';') -contains $WinGetPath))
    { 
    If ($env:path -match ";$")
      {
        $env:path +=  $WinGetPath + ";"
      }
    else
      {
        $env:path +=  ";" + $WinGetPath + ";"			
      }
    write-host "Winget path $WinGetPath added to environment variable"
    }
  else
    { 
      write-host "Winget path already exists in registry."
    }
}
Perfect.hr - kresimir ivkovic Software Developer