11<#
22. SYNOPSIS
33Install apps with Winget through Intune or SCCM.
4- Can be used standalone.
4+ ( Can be used standalone.) - Deprecated in favor of Winget-AutoUpdate .
55
66. DESCRIPTION
77Allow to run Winget in System Context to install your apps.
8- https://github.com/Romanitho/Winget-Install
8+ ( https://github.com/Romanitho/Winget-Install) - Deprecated in favor of Winget-AutoUpdate.
99
1010. PARAMETER AppIDs
1111Forward Winget App ID to install. For multiple apps, separate with ",". Case sensitive.
@@ -90,59 +90,39 @@ function Confirm-Exist ($AppID) {
9090
9191# Check if install modifications exist in "mods" directory
9292function Test-ModsInstall ($AppID ) {
93- # Check current location
94- if (Test-Path " .\mods\$AppID -preinstall.ps1" ) {
95- $ModsPreInstall = " .\mods\$AppID -preinstall.ps1"
96- }
97- # Else, check in WAU mods
98- elseif (Test-Path " $WAUModsLocation \$AppID -preinstall.ps1" ) {
99- $ModsPreInstall = " $WAUModsLocation \$AppID -preinstall.ps1"
100- }
101-
102- if (Test-Path " .\mods\$AppID -install.ps1" ) {
103- $ModsInstall = " .\mods\$AppID -install.ps1"
104- }
105- elseif (Test-Path " $WAUModsLocation \$AppID -install.ps1" ) {
106- $ModsInstall = " $WAUModsLocation \$AppID -install.ps1"
107- }
108-
109- if (Test-Path " .\mods\$AppID -installed-once.ps1" ) {
110- $ModsInstalledOnce = " .\mods\$AppID -installed-once.ps1"
111- }
112-
113- if (Test-Path " .\mods\$AppID -installed.ps1" ) {
114- $ModsInstalled = " .\mods\$AppID -installed.ps1"
115- }
116- elseif (Test-Path " $WAUModsLocation \$AppID -installed.ps1" ) {
117- $ModsInstalled = " $WAUModsLocation \$AppID -installed.ps1"
93+ if (Test-Path " $Mods \$AppID -*" ) {
94+ if (Test-Path " $Mods \$AppID -preinstall.ps1" ) {
95+ $ModsPreInstall = " $Mods \$AppID -preinstall.ps1"
96+ }
97+ if (Test-Path " $Mods \$AppID -override.txt" ) {
98+ $ModsOverride = (Get-Content " $Mods \$AppID -override.txt" - Raw).Trim()
99+ }
100+ if (Test-Path " $Mods \$AppID -custom.txt" ) {
101+ $ModsCustom = (Get-Content " $Mods \$AppID -custom.txt" - Raw).Trim()
102+ }
103+ if (Test-Path " $Mods \$AppID -install.ps1" ) {
104+ $ModsInstall = " $Mods \$AppID -install.ps1"
105+ }
106+ if (Test-Path " $Mods \$AppID -installed.ps1" ) {
107+ $ModsInstalled = " $Mods \$AppID -installed.ps1"
108+ }
118109 }
119110
120- return $ModsPreInstall , $ModsInstall , $ModsInstalledOnce , $ModsInstalled
111+ return $ModsPreInstall , $ModsOverride , $ModsCustom , $ModsInstall , $ModsInstalled
121112}
122113
123114# Check if uninstall modifications exist in "mods" directory
124115function Test-ModsUninstall ($AppID ) {
125- # Check current location
126- if (Test-Path " .\mods\$AppID -preuninstall.ps1" ) {
127- $ModsPreUninstall = " .\mods\$AppID -preuninstall.ps1"
128- }
129- # Else, check in WAU mods
130- elseif (Test-Path " $WAUModsLocation \$AppID -preuninstall.ps1" ) {
131- $ModsPreUninstall = " $WAUModsLocation \$AppID -preuninstall.ps1"
132- }
133-
134- if (Test-Path " .\mods\$AppID -uninstall.ps1" ) {
135- $ModsUninstall = " .\mods\$AppID -uninstall.ps1"
136- }
137- elseif (Test-Path " $WAUModsLocation \$AppID -uninstall.ps1" ) {
138- $ModsUninstall = " $WAUModsLocation \$AppID -uninstall.ps1"
139- }
140-
141- if (Test-Path " .\mods\$AppID -uninstalled.ps1" ) {
142- $ModsUninstalled = " .\mods\$AppID -uninstalled.ps1"
143- }
144- elseif (Test-Path " $WAUModsLocation \$AppID -uninstalled.ps1" ) {
145- $ModsUninstalled = " $WAUModsLocation \$AppID -uninstalled.ps1"
116+ if (Test-Path " $Mods \$AppID -*" ) {
117+ if (Test-Path " $Mods \$AppID -preuninstall.ps1" ) {
118+ $ModsPreUninstall = " $Mods \$AppID -preinstall.ps1"
119+ }
120+ if (Test-Path " $Mods \$AppID -uninstall.ps1" ) {
121+ $ModsUninstall = " $Mods \$AppID -uninstall.ps1"
122+ }
123+ if (Test-Path " $Mods \$AppID -uninstalled.ps1" ) {
124+ $ModsUninstalled = " $Mods \$AppID -uninstalled.ps1"
125+ }
146126 }
147127
148128 return $ModsPreUninstall , $ModsUninstall , $ModsUninstalled
@@ -152,8 +132,8 @@ function Test-ModsUninstall ($AppID) {
152132function Install-App ($AppID , $AppArgs ) {
153133 $IsInstalled = Confirm-Installation $AppID
154134 if (! ($IsInstalled ) -or $AllowUpgrade ) {
155- # Check if mods exist (or already exist) for preinstall/install/installedonce /installed
156- $ModsPreInstall , $ModsInstall , $ModsInstalledOnce , $ModsInstalled = Test-ModsInstall $ ($AppID )
135+ # Check if mods exist (or already exist) for preinstall/override/custom/install /installed
136+ $ModsPreInstall , $ModsOverride , $ModsCustom , $ModsInstall , $ModsInstalled = Test-ModsInstall $ ($AppID )
157137
158138 # If PreInstall script exist
159139 if ($ModsPreInstall ) {
@@ -163,7 +143,18 @@ function Install-App ($AppID, $AppArgs) {
163143
164144 # Install App
165145 Write-ToLog " -> Installing $AppID ..." " Yellow"
166- $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h $AppArgs " -split " "
146+ if ($ModsOverride ) {
147+ Write-ToLog " -> Arguments (overriding default): $ModsOverride "
148+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget --override $ModsOverride " -split " "
149+ }
150+ elseif ($ModsCustom ) {
151+ Write-ToLog " -> Arguments (customized default): $ModsCustom "
152+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget --custom $ModsCustom " -split " "
153+ }
154+ else {
155+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h $AppArgs " -split " "
156+ }
157+
167158 Write-ToLog " -> Running: `" $Winget `" $WingetArgs "
168159 & " $Winget " $WingetArgs | Where-Object { $_ -notlike " *" } | Tee-Object - file $LogFile - Append
169160
@@ -186,17 +177,6 @@ function Install-App ($AppID, $AppArgs) {
186177 & " $ModsInstalled "
187178 }
188179
189- # Add mods if deployed from Winget-Install
190- if (Test-Path " .\mods\$AppID -*" ) {
191- # Check if WAU default install path exists
192- $Mods = " $WAUModsLocation "
193- if (Test-Path $Mods ) {
194- # Add mods
195- Write-ToLog " -> Add modifications for $AppID to WAU 'mods'"
196- Copy-Item " .\mods\$AppID -*" - Destination " $Mods " - Exclude " *installed-once*" , " *uninstall*" - Force
197- }
198- }
199-
200180 # Add to WAU White List if set
201181 if ($WAUWhiteList ) {
202182 Add-WAUWhiteList $AppID
@@ -244,17 +224,6 @@ function Uninstall-App ($AppID, $AppArgs) {
244224 & " $ModsUninstalled "
245225 }
246226
247- # Remove mods if deployed from Winget-Install
248- if (Test-Path " .\mods\$AppID -*" ) {
249- # Check if WAU default install path exists
250- $Mods = " $WAUModsLocation "
251- if (Test-Path " $Mods \$AppID *" ) {
252- Write-ToLog " -> Remove $AppID modifications from WAU 'mods'"
253- # Remove mods
254- Remove-Item - Path " $Mods \$AppID -*" - Exclude " *uninstall*" - Force
255- }
256- }
257-
258227 # Remove from WAU White List if set
259228 if ($WAUWhiteList ) {
260229 Remove-WAUWhiteList $AppID
@@ -321,7 +290,9 @@ $Script:IsElevated = $CurrentPrincipal.IsInRole([Security.Principal.WindowsBuilt
321290# Get WAU Installed location
322291$WAURegKey = " HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\"
323292$Script :WAUInstallLocation = Get-ItemProperty $WAURegKey - ErrorAction SilentlyContinue | Select-Object - ExpandProperty InstallLocation
324- $Script :WAUModsLocation = Join-Path - Path $WAUInstallLocation - ChildPath " mods"
293+ # Get the Working Dir
294+ [string ]$Script :WorkingDir = $PSScriptRoot
295+ $Mods = " $WorkingDir \mods"
325296
326297# Log file & LogPath initialization
327298if ($IsElevated ) {
0 commit comments