Param( #Defines Parameters that will be used within this script. [Parameter(Mandatory=$true)] #This is an attribute applied to the parameter. It specifies that a parameter is required. [string]$WingetPackageID #[String] is the type of parameter. $WingetPackageID is the name of the parameter. ) #Parameters will be defined in the install/uninstall arguements of the Intune Application when adding the app. For example: #powershell.exe -ExecutionPolicy Bypass -File .\WingetInstall.ps1 -WingetPackageID "Valve.Steam" #powershell.exe -ExecutionPolicy Bypass -File .\WingetUninstall.ps1 -WingetPackageID "Valve.Steam" #This begins recording a transcript of this script and saves it to the below path Start-Transcript -Path "C:\Users\Public\Downloads\$($WingetPackageID)_Install.log" -Append #Writes in the console the below message Write-Host "Starting Transcript for Winget Installation" -ForegroundColor Green try { #Attempts to run the below code #Writes in the console the below message Write-Host "Attempting to install $($WingetPackageID) via Winget" #Resolves the path of Winget.exe within the current user's appdata. $ResolveWingetPath = Join-Path $env:USERPROFILE 'AppData\Local\Microsoft\WindowsApps\winget.exe' if ($ResolveWingetPath){ #Checks if ResolveWingetPath has data within it #Writes in the console what the value of WingetPath is Write-Host "winget.exe found at: $ResolveWingetPath" } else { #If unable to find Winget Path. It will present this in the console. Throw "winget.exe not found in the current user's profile." } #'&' invokes/executes Winget and allows us to use winget linked arguements such as 'install' #Attempts to install Winget application and presents current winget version & $ResolveWingetPath --version & $ResolveWingetPath install --exact $WingetPackageID --silent --accept-source-agreements --accept-package-agreements --disable-interactivity #--accept-source-agreements --accept-package-agreements - This is needed as devices that have never ran Winget performed will be prompted to accept terms and conditions. This bypasses this. #--disable-interactivity - Attempts to disable user interactivity } Catch { #Will run the below code if the above try fails Throw "Failed to install Package. [$($_.Exception.Message)] See: %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir" #This is the path for Winget logs. There will only be logs here if Winget attempted to install/uninstall. } Stop-Transcript