2023-10-03 08:18:00 +00:00
|
|
|
#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-10-03 08:18:00 +00:00
|
|
|
}
|
2023-11-20 15:30:46 +00:00
|
|
|
catch {
|
|
|
|
#Get User context Winget Location
|
2023-10-24 16:30:56 +00:00
|
|
|
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-10-03 08:18:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 15:30:46 +00:00
|
|
|
return $WingetCmd
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-11-20 15:30:46 +00:00
|
|
|
}
|