From 6362be61a030047463a967fa974a50c66f87bc22 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 5 Apr 2022 12:15:43 +0200 Subject: [PATCH 1/2] Add support for White List for WAU --- winget-install.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/winget-install.ps1 b/winget-install.ps1 index 0d51dd4..4ea127f 100644 --- a/winget-install.ps1 +++ b/winget-install.ps1 @@ -16,6 +16,10 @@ To uninstall app. Works with AppIDs .PARAMETER LogPath Used to specify logpath. Default is same folder as Winget-Autoupdate project +.PARAMETER WAUWhiteList +Adds the app to the Winget-AutoUpdate White List. More info: https://github.com/Romanitho/Winget-AutoUpdate +If '-Uninstall' is used, it removes the app from WAU White List. + .EXAMPLE .\winget-install.ps1 -AppIDs 7zip.7zip @@ -30,7 +34,8 @@ Used to specify logpath. Default is same folder as Winget-Autoupdate project param( [Parameter(Mandatory=$True,ParameterSetName="AppIDs")] [String[]] $AppIDs, [Parameter(Mandatory=$False)] [Switch] $Uninstall, - [Parameter(Mandatory=$False)] [String] $LogPath = "$env:ProgramData\Winget-Install\logs" + [Parameter(Mandatory=$False)] [String] $LogPath = "$env:ProgramData\Winget-AutoUpdate\logs", + [Parameter(Mandatory=$False)] [Switch] $WAUWhiteList ) @@ -45,7 +50,7 @@ function Init { #Log file $Script:LogFile = "$LogPath\install.log" - Write-Log "Log path is: $LogFile" + Write-Host "Log path is: $LogFile" #Log Header if ($Uninstall){ @@ -160,6 +165,31 @@ function Uninstall-App ($AppID){ } } +#Function to Add app to WAU white list +function Add-WAUWhiteList ($AppID){ + #Check if WAU default intall path exists + $WhiteList = "$env:ProgramData\Winget-AutoUpdate\included_apps.txt" + if (Test-Path $WhiteList){ + Write-Log "Add $AppID to WAU included_apps.txt" + #Add App to "included_apps.txt" + Add-Content -path $WhiteList -Value "`n$AppID" -Force + #Remove duplicate and blank lines + $file = Get-Content $WhiteList | Select-Object -Unique | Where-Object {$_.trim() -ne ""} | Sort-Object + $file | Out-File $WhiteList + } +} + +#Function to Remove app from WAU white list +function Remove-WAUWhiteList ($AppID){ + #Check if WAU default intall path exists + $WhiteList = "$env:ProgramData\Winget-AutoUpdate\included_apps.txt" + if (Test-Path $WhiteList){ + Write-Log "Remove $AppID to WAU included_apps.txt" + #Remove app from list + $file = Get-Content $WhiteList | Where-Object {$_ -notmatch "$AppID"} + $file | Out-File $WhiteList + } +} <# MAIN #> @@ -185,9 +215,17 @@ foreach ($AppID in $AppIDs){ #Install or Uninstall command if ($Uninstall){ Uninstall-App $AppID + #Add to WAU White List if set + if ($WAUWhiteList){ + Remove-WAUWhiteList $AppID + } } else{ Install-App $AppID + #Remove from WAU White List if set + if ($WAUWhiteList){ + Add-WAUWhiteList $AppID + } } } Start-Sleep 3 From 10cbf16c57b5096bf658189722df2c819f3bc0e5 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 5 Apr 2022 15:09:33 +0200 Subject: [PATCH 2/2] Update winget-install.ps1 --- winget-install.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/winget-install.ps1 b/winget-install.ps1 index 4ea127f..6c04b55 100644 --- a/winget-install.ps1 +++ b/winget-install.ps1 @@ -26,6 +26,9 @@ If '-Uninstall' is used, it removes the app from WAU White List. .EXAMPLE .\winget-install.ps1 -AppIDs 7zip.7zip -Uninstall +.EXAMPLE +.\winget-install.ps1 -AppIDs 7zip.7zip -WAUWhiteList + .EXAMPLE .\winget-install.ps1 -AppIDs 7zip.7zip,notepad++.notepad++ -LogPath "C:\temp\logs" #> @@ -232,4 +235,4 @@ foreach ($AppID in $AppIDs){ } Write-Log "### END REQUEST ###" "Magenta" -Start-Sleep 3 \ No newline at end of file +Start-Sleep 3