11<#
22. SYNOPSIS
33Install apps with Winget through Intune or SCCM.
4- (Can be used standalone.) - Deprecated in favor of Winget-AutoUpdate.
54
65. DESCRIPTION
76Allow to run Winget in System Context to install your apps.
8- (https://github.com/Romanitho/Winget-Install) - Deprecated in favor of Winget-AutoUpdate.
97
108. PARAMETER AppIDs
119Forward Winget App ID to install. For multiple apps, separate with ",". Case sensitive.
4846 [Parameter (Mandatory = $False )] [Switch ] $Uninstall ,
4947 [Parameter (Mandatory = $False )] [String ] $LogPath ,
5048 [Parameter (Mandatory = $False )] [Switch ] $WAUWhiteList ,
51- [Parameter (Mandatory = $False )] [Switch ] $AllowUpgrade
49+ [Parameter (Mandatory = $False )] [Switch ] $AllowUpgrade ,
50+ [Parameter (Mandatory = $False )] [String ] $Source = " winget"
5251)
5352
5453
7675# Check if App exists in Winget Repository
7776function Confirm-Exist ($AppID ) {
7877 # Check is app exists in the winget repository
79- $WingetApp = & $winget show -- Id $AppID - e -- accept- source- agreements - s winget | Out-String
78+ $WingetApp = & $winget show -- Id $AppID - e -- accept- source- agreements - s $Source | Out-String
8079
8180 # Return if AppID exists
8281 if ($WingetApp -match [regex ]::Escape($AppID )) {
@@ -139,8 +138,8 @@ function Test-ModsUninstall ($AppID) {
139138}
140139
141140# Install function
142- function Install-App ($AppID , $AppArgs ) {
143- $IsInstalled = Confirm-Installation $AppID
141+ function Install-App ($AppID , $AppArgs , $Source = ' winget ' ) {
142+ $IsInstalled = Confirm-Installation $AppID - src $Source
144143 if (! ($IsInstalled ) -or $AllowUpgrade ) {
145144 # Check if mods exist (or already exist) for preinstall/override/custom/arguments/install/installed
146145 $ModsPreInstall , $ModsOverride , $ModsCustom , $ModsArguments , $ModsInstall , $ModsInstalled = Test-ModsInstall $ ($AppID )
@@ -159,21 +158,21 @@ function Install-App ($AppID, $AppArgs) {
159158 Write-ToLog " -> Installing $AppID ..." " DarkYellow"
160159 if ($ModsOverride ) {
161160 Write-ToLog " -> Arguments (overriding default): $ModsOverride " # Without -h (user overrides default)
162- $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget --override $ModsOverride " -split " "
161+ $WingetArgs = @ ( " install" , " --id" , $AppID , " -e " , " --accept-package-agreements" , " --accept-source-agreements" , " -s " , $Source , " --override" , $ModsOverride )
163162 }
164163 elseif ($ModsCustom ) {
165164 Write-ToLog " -> Arguments (customizing default): $ModsCustom " # With -h (user customizes default)
166- $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h --custom $ModsCustom " -split " "
165+ $WingetArgs = @ ( " install" , " --id" , $AppID , " -e " , " --accept-package-agreements" , " --accept-source-agreements" , " -s " , $Source , " -h " , " --custom" , $ModsCustom )
167166 }
168167 elseif ($ModsArguments -or (-not [string ]::IsNullOrWhiteSpace($AppArgs ))) {
169168 # Prioritize ModsArguments from file over AppArgs from command line
170169 $finalArgs = if ($ModsArguments ) { $ModsArguments } else { $AppArgs }
171170 Write-ToLog " -> Arguments (winget-level): $finalArgs " # Winget parameters with -h
172171 $argArray = ConvertTo-WingetArgumentArray $finalArgs
173- $WingetArgs = @ (" install" , " --id" , $AppID , " -e" , " --accept-package-agreements" , " --accept-source-agreements" , " -s" , " winget " ) + $argArray + @ (" -h" )
172+ $WingetArgs = @ (" install" , " --id" , $AppID , " -e" , " --accept-package-agreements" , " --accept-source-agreements" , " -s" , $Source ) + $argArray + @ (" -h" )
174173 }
175174 else {
176- $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h" -split " "
175+ $WingetArgs = @ ( " install" , " --id" , $AppID , " -e " , " --accept-package-agreements" , " --accept-source-agreements" , " -s " , $Source , " -h" )
177176 }
178177
179178 Write-ToLog " -> Running: `" $Winget `" $WingetArgs "
@@ -185,7 +184,7 @@ function Install-App ($AppID, $AppArgs) {
185184 }
186185
187186 # Check if install is ok
188- $IsInstalled = Confirm-Installation $AppID
187+ $IsInstalled = Confirm-Installation $AppID - src $Source
189188 if ($IsInstalled ) {
190189 Write-ToLog " -> $AppID successfully installed." " Green"
191190
@@ -209,8 +208,8 @@ function Install-App ($AppID, $AppArgs) {
209208}
210209
211210# Uninstall function
212- function Uninstall-App ($AppID , $AppArgs ) {
213- $IsInstalled = Confirm-Installation $AppID
211+ function Uninstall-App ($AppID , $AppArgs , $Source = ' winget ' ) {
212+ $IsInstalled = Confirm-Installation $AppID - src $Source
214213 if ($IsInstalled ) {
215214 # Check if mods exist (or already exist) for preuninstall/uninstall/uninstalled
216215 $ModsPreUninstall , $ModsUninstall , $ModsUninstalled = Test-ModsUninstall $AppID
@@ -244,7 +243,7 @@ function Uninstall-App ($AppID, $AppArgs) {
244243 }
245244
246245 # Check if uninstall is ok
247- $IsInstalled = Confirm-Installation $AppID
246+ $IsInstalled = Confirm-Installation $AppID - src $Source
248247 if (! ($IsInstalled )) {
249248 Write-ToLog " -> $AppID successfully uninstalled." " Green"
250249 if ($ModsUninstalled ) {
@@ -399,14 +398,14 @@ if ($Winget) {
399398
400399 # Install or Uninstall command
401400 if ($Uninstall ) {
402- Uninstall-App $AppID $AppArgs
401+ Uninstall-App $AppID $AppArgs $Source
403402 }
404403 else {
405404 # Check if app exists on Winget Repo
406405 $Exists = Confirm-Exist $AppID
407406 if ($Exists ) {
408407 # Install
409- Install-App $AppID $AppArgs
408+ Install-App $AppID $AppArgs $Source
410409 }
411410 }
412411
0 commit comments