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

23 lines
823 B
PowerShell
Raw Permalink Normal View History

#Function to get the winget command regarding execution context (User, System...)
Function Get-WingetCmd {
2023-11-20 15:30:46 +00:00
$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
}
2023-11-20 15:30:46 +00:00
catch {
#Get User context Winget Location
if (Test-Path "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe") {
2023-11-20 15:30:46 +00:00
$WingetCmd = "$env:LocalAppData\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\winget.exe"
}
}
2023-11-20 15:30:46 +00:00
return $WingetCmd
2023-11-20 15:30:46 +00:00
}