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

24 lines
824 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
2024-09-02 14:10:21 +00:00
}