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 -preuninstall.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,23 +132,38 @@ 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 ) {
160- Write-ToLog " -> Modifications for $AppID before install are being applied..." " Yellow"
161- & " $ModsPreInstall "
140+ Write-ToLog " Modifications for $AppID before install are being applied..." " DarkYellow"
141+ $preInstallResult = & " $ModsPreInstall "
142+ if ($preInstallResult -eq $false ) {
143+ Write-ToLog " PreInstall script for $AppID requested to skip this installation" " Yellow"
144+ return # Exit the function early
145+ }
162146 }
163147
164148 # Install App
165- Write-ToLog " -> Installing $AppID ..." " Yellow"
166- $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h $AppArgs " -split " "
149+ Write-ToLog " -> Installing $AppID ..." " DarkYellow"
150+ if ($ModsOverride ) {
151+ Write-ToLog " -> Arguments (overriding default): $ModsOverride " # Without -h (user overrides default)
152+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget --override $ModsOverride " -split " "
153+ }
154+ elseif ($ModsCustom ) {
155+ Write-ToLog " -> Arguments (customizing default): $ModsCustom " # With -h (user customizes default)
156+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h --custom $ModsCustom " -split " "
157+ }
158+ else {
159+ $WingetArgs = " install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h $AppArgs " -split " "
160+ }
161+
167162 Write-ToLog " -> Running: `" $Winget `" $WingetArgs "
168163 & " $Winget " $WingetArgs | Where-Object { $_ -notlike " *" } | Tee-Object - file $LogFile - Append
169164
170165 if ($ModsInstall ) {
171- Write-ToLog " -> Modifications for $AppID during install are being applied..." " Yellow "
166+ Write-ToLog " -> Modifications for $AppID during install are being applied..." " DarkYellow "
172167 & " $ModsInstall "
173168 }
174169
@@ -177,26 +172,11 @@ function Install-App ($AppID, $AppArgs) {
177172 if ($IsInstalled ) {
178173 Write-ToLog " -> $AppID successfully installed." " Green"
179174
180- if ($ModsInstalledOnce ) {
181- Write-ToLog " -> Modifications for $AppID after install (one time) are being applied..." " Yellow"
182- & " $ModsInstalledOnce "
183- }
184- elseif ($ModsInstalled ) {
185- Write-ToLog " -> Modifications for $AppID after install are being applied..." " Yellow"
175+ if ($ModsInstalled ) {
176+ Write-ToLog " -> Modifications for $AppID after install are being applied..." " DarkYellow"
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
@@ -220,18 +200,22 @@ function Uninstall-App ($AppID, $AppArgs) {
220200
221201 # If PreUninstall script exist
222202 if ($ModsPreUninstall ) {
223- Write-ToLog " -> Modifications for $AppID before uninstall are being applied..." " Yellow"
224- & " $ModsPreUninstall "
203+ Write-ToLog " Modifications for $AppID before uninstall are being applied..." " DarkYellow"
204+ $preUnInstallResult = & " $ModsPreUnInstall "
205+ if ($preUnInstallResult -eq $false ) {
206+ Write-ToLog " PreUnInstall script for $AppID requested to skip this uninstallation" " Yellow"
207+ return # Exit the function early
208+ }
225209 }
226210
227211 # Uninstall App
228- Write-ToLog " -> Uninstalling $AppID ..." " Yellow "
212+ Write-ToLog " -> Uninstalling $AppID ..." " DarkYellow "
229213 $WingetArgs = " uninstall --id $AppID -e --accept-source-agreements -h $AppArgs " -split " "
230214 Write-ToLog " -> Running: `" $Winget `" $WingetArgs "
231215 & " $Winget " $WingetArgs | Where-Object { $_ -notlike " *" } | Tee-Object - file $LogFile - Append
232216
233217 if ($ModsUninstall ) {
234- Write-ToLog " -> Modifications for $AppID during uninstall are being applied..." " Yellow "
218+ Write-ToLog " -> Modifications for $AppID during uninstall are being applied..." " DarkYellow "
235219 & " $ModsUninstall "
236220 }
237221
@@ -240,21 +224,10 @@ function Uninstall-App ($AppID, $AppArgs) {
240224 if (! ($IsInstalled )) {
241225 Write-ToLog " -> $AppID successfully uninstalled." " Green"
242226 if ($ModsUninstalled ) {
243- Write-ToLog " -> Modifications for $AppID after uninstall are being applied..." " Yellow "
227+ Write-ToLog " -> Modifications for $AppID after uninstall are being applied..." " DarkYellow "
244228 & " $ModsUninstalled "
245229 }
246230
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-
258231 # Remove from WAU White List if set
259232 if ($WAUWhiteList ) {
260233 Remove-WAUWhiteList $AppID
@@ -330,7 +303,9 @@ $Script:IsElevated = $CurrentPrincipal.IsInRole([Security.Principal.WindowsBuilt
330303# Get WAU Installed location
331304$WAURegKey = " HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\"
332305$Script :WAUInstallLocation = Get-ItemProperty $WAURegKey - ErrorAction SilentlyContinue | Select-Object - ExpandProperty InstallLocation
333- $Script :WAUModsLocation = Join-Path - Path $WAUInstallLocation - ChildPath " mods"
306+
307+ # Use the Working Dir (even if it is from a symlink)
308+ $Mods = " $realPath \mods"
334309
335310# Log file & LogPath initialization
336311if ($IsElevated ) {
0 commit comments