wingetautoupdate/Sources/Winget-AutoUpdate/functions/Get-WingetCmd.ps1

24 lines
824 B
PowerShell

#Function to get the winget command regarding execution context (User, System...)
Function Get-WingetCmd {
$WingetCmd = $null
#Get WinGet Path
try {
#Get Admin Context Winget Location
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
#If multiple versions, pick most recent one
$WingetCmd = $WingetInfo[-1].FileName
}
catch {
#Get User context Winget Location
if (Test-Path "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe") {
$WingetCmd = "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe"
}
}
return $WingetCmd
}