A PowerShell script to install/manage applications using WinGet - Common use case include InTune, and other endpoint management products. Detection script automaatically check local installed version against latest winget available version or a defined fixed target version.
- Dynamically finds the WinGet directory to be used under System Context.
- Kill selected process before WinGet command
- Allows running pre and post script before installation
- Detection script that dynamically finds latest package available trough WinGet
- Requirement script to allow creating packages for update purposes only
- Logs to $env:ProgramData\WinGet-WrapperLogs (Usually C:\ProgramData\WinGet-WrapperLogs)
- Dynamically detect if running in user or system context
- Performs automatic cleanup of log files older than 60 days.
WinGet have a few limitations in terms of automation and is not integrated with common endpoints management products.
System Context is not possible by using "winget" as the .exe location must be found and this location is not static due to versioning in the directory name.
Newer Windows OS build that includes the WinGet natively in the OS
Windows 10 20H2 or newer should be enough
Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "PackageName for log file" -StopProcess "kill process using Stop-Process (do not add .exe)" -PreScript "somefile.ps1" -PostScript "somefile.ps1" -ArgumentList "Arguments Passed to WinGet.exe"
Matches locally installed version with newest available version using WinGet or specified version using $TargetVersion Can be setup to accept newer installed version locally $AcceptNewerVersion
Checks if application is detected locally. If not detected will not attempt update/install To be used when only wanting to update if application is already installed. (Update Only)
Outputs either "Installed" or "Not Installed"
Application Installation
In InTune create an Windows app (Win32) and upload WinGet-Wrapper.InTuneWin as the package file.
Install: Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -ArgumentList "install --exact --id VideoLAN.VLC --silent --accept-package-agreements --accept-source-agreements --scope machine"
Uninstall: Powershell.exe -NoLogo -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File WinGet-Wrapper.ps1 -PackageName "VideoLAN.VLC" -StopProcess "VLC" -ArgumentList "Uninstall --exact --id VideoLAN.VLC --silent --accept-source-agreements --scope machine"
Change the $id variable to match the package id in the detection script and upload it ($id = "VideoLAN.VLC")
If specific version is required change the $TargetVersion (Ex. $TargetVersion = "1.0.0.0")
Application Update Only
Perform the same steps as in "Application Installation". Setup Requirement rule script with return string value of "Installed"