Add White List Option
parent
acc36bf2ad
commit
758b2608ae
|
@ -95,13 +95,14 @@ function Install-WingetAutoUpdate{
|
||||||
New-Item -ItemType Directory -Force -Path $WingetUpdatePath
|
New-Item -ItemType Directory -Force -Path $WingetUpdatePath
|
||||||
}
|
}
|
||||||
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
#White List or Black List apps
|
#White List or Black List apps
|
||||||
if ($UseWhiteList){
|
if ($UseWhiteList){
|
||||||
if (Test-Path "$PSScriptRoot\included_apps.txt"){
|
if (Test-Path "$PSScriptRoot\included_apps.txt"){
|
||||||
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file"
|
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<app>
|
<app>
|
||||||
<name>Winget-AutoUpdate (WAU)</name>
|
<name>Winget-AutoUpdate (WAU)</name>
|
||||||
<version>1.6.3</version>
|
<version>1.7.0</version>
|
||||||
<author>Romanitho</author>
|
<author>Romanitho</author>
|
||||||
<info>https://github.com/Romanitho/Winget-AutoUpdate</info>
|
<info>https://github.com/Romanitho/Winget-AutoUpdate</info>
|
||||||
</app>
|
</app>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
function Get-IncludedApps{
|
||||||
|
if (Test-Path "$WorkingDir\included_apps.txt"){
|
||||||
|
return Get-Content -Path "$WorkingDir\included_apps.txt"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
function Get-WAUConfig{
|
||||||
|
|
||||||
|
[xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
#Check if WAU is configured for Black or White List
|
||||||
|
if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){
|
||||||
|
Write-Log "WAU uses White List config"
|
||||||
|
$Script:UseWhiteList = $true
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Write-Log "WAU uses Black List config"
|
||||||
|
$Script:UseWhiteList = $false
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,15 +10,15 @@ function Get-WingetOutdatedApps {
|
||||||
$WingetPath = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe").Path
|
$WingetPath = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe").Path
|
||||||
#Get Winget Location in User context
|
#Get Winget Location in User context
|
||||||
if ($WingetCmd){
|
if ($WingetCmd){
|
||||||
$Script:winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
|
$Script:Winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
|
||||||
}
|
}
|
||||||
#Get Winget Location in System context (WinGet < 1.17)
|
#Get Winget Location in System context (WinGet < 1.17)
|
||||||
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
||||||
$Script:winget = "$WingetPath\AppInstallerCLI.exe"
|
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
|
||||||
}
|
}
|
||||||
#Get Winget Location in System context (WinGet > 1.17)
|
#Get Winget Location in System context (WinGet > 1.17)
|
||||||
elseif (Test-Path "$WingetPath\winget.exe"){
|
elseif (Test-Path "$WingetPath\winget.exe"){
|
||||||
$Script:winget = "$WingetPath\winget.exe"
|
$Script:Winget = "$WingetPath\winget.exe"
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Write-Log "Winget not installed !" "Red"
|
Write-Log "Winget not installed !" "Red"
|
||||||
|
@ -26,10 +26,10 @@ function Get-WingetOutdatedApps {
|
||||||
}
|
}
|
||||||
|
|
||||||
#Run winget to list apps and accept source agrements (necessary on first run)
|
#Run winget to list apps and accept source agrements (necessary on first run)
|
||||||
& $upgradecmd list --accept-source-agreements | Out-Null
|
& $Winget list --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
#Get list of available upgrades on winget format
|
#Get list of available upgrades on winget format
|
||||||
$upgradeResult = & $upgradecmd upgrade | Out-String
|
$upgradeResult = & $Winget upgrade | Out-String
|
||||||
|
|
||||||
#Start Convertion of winget format to an array. Check if "-----" exists
|
#Start Convertion of winget format to an array. Check if "-----" exists
|
||||||
if (!($upgradeResult -match "-----")){
|
if (!($upgradeResult -match "-----")){
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
Function Update-App ($app) {
|
||||||
|
|
||||||
|
#Send available update notification
|
||||||
|
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
|
||||||
|
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
|
||||||
|
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
|
||||||
|
$MessageType = "info"
|
||||||
|
$Balise = $($app.Name)
|
||||||
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
|
|
||||||
|
#Winget upgrade
|
||||||
|
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
||||||
|
#Run Winget Upgrade command
|
||||||
|
& $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||||
|
|
||||||
|
#Check if application updated properly
|
||||||
|
$CheckOutdated = Get-WingetOutdatedApps
|
||||||
|
$FailedToUpgrade = $false
|
||||||
|
foreach ($CheckApp in $CheckOutdated){
|
||||||
|
if ($($CheckApp.Id) -eq $($app.Id)) {
|
||||||
|
#If app failed to upgrade, run Install command
|
||||||
|
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||||
|
#Check if application installed properly
|
||||||
|
$CheckOutdated2 = Get-WingetOutdatedApps
|
||||||
|
foreach ($CheckApp2 in $CheckOutdated2){
|
||||||
|
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
||||||
|
$FailedToUpgrade = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
||||||
|
|
||||||
|
#Notify installation
|
||||||
|
if ($FailedToUpgrade -eq $false){
|
||||||
|
#Send success updated app notification
|
||||||
|
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
|
||||||
|
|
||||||
|
#Send Notif
|
||||||
|
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
|
||||||
|
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
|
||||||
|
$MessageType = "success"
|
||||||
|
$Balise = $($app.Name)
|
||||||
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
|
|
||||||
|
$InstallOK += 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#Send failed updated app notification
|
||||||
|
Write-Log "$($app.Name) update failed." "Red"
|
||||||
|
|
||||||
|
#Send Notif
|
||||||
|
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
||||||
|
$Message = $NotifLocale.local.outputs.output[4].message
|
||||||
|
$MessageType = "error"
|
||||||
|
$Balise = $($app.Name)
|
||||||
|
Start-NotifTask $Title $Message $MessageType $Balise
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,8 +35,14 @@ if (Test-Network){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get exclude apps list
|
#Get White or Black list
|
||||||
$toSkip = Get-ExcludedApps
|
Get-WAUConfig
|
||||||
|
if ($UseWhiteList){
|
||||||
|
$toUpdate = Get-IncludedApps
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$toSkip = Get-ExcludedApps
|
||||||
|
}
|
||||||
|
|
||||||
#Get outdated Winget packages
|
#Get outdated Winget packages
|
||||||
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
||||||
|
@ -51,77 +57,40 @@ if (Test-Network){
|
||||||
}
|
}
|
||||||
|
|
||||||
#Count good update installations
|
#Count good update installations
|
||||||
$InstallOK = 0
|
$Script:InstallOK = 0
|
||||||
|
|
||||||
#For each app, notify and update
|
#If White List
|
||||||
foreach ($app in $outdated){
|
if ($UseWhiteList){
|
||||||
|
#For each app, notify and update
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
foreach ($app in $outdated){
|
||||||
|
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
||||||
#Send available update notification
|
Update-App $app
|
||||||
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
|
|
||||||
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
|
|
||||||
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
|
|
||||||
$MessageType = "info"
|
|
||||||
$Balise = $($app.Name)
|
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
|
||||||
|
|
||||||
#Winget upgrade
|
|
||||||
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
|
||||||
#Run Winget Upgrade command
|
|
||||||
& $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
|
||||||
|
|
||||||
#Check if application updated properly
|
|
||||||
$CheckOutdated = Get-WingetOutdatedApps
|
|
||||||
$FailedToUpgrade = $false
|
|
||||||
foreach ($CheckApp in $CheckOutdated){
|
|
||||||
if ($($CheckApp.Id) -eq $($app.Id)) {
|
|
||||||
#If app failed to upgrade, run Install command
|
|
||||||
& $upgradecmd install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
|
||||||
#Check if application installed properly
|
|
||||||
$CheckOutdated2 = Get-WingetOutdatedApps
|
|
||||||
foreach ($CheckApp2 in $CheckOutdated2){
|
|
||||||
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
|
||||||
$FailedToUpgrade = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
|
|
||||||
|
|
||||||
#Notify installation
|
|
||||||
if ($FailedToUpgrade -eq $false){
|
|
||||||
#Send success updated app notification
|
|
||||||
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
|
|
||||||
|
|
||||||
#Send Notif
|
|
||||||
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
|
|
||||||
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
|
|
||||||
$MessageType = "success"
|
|
||||||
$Balise = $($app.Name)
|
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
|
||||||
|
|
||||||
$InstallOK += 1
|
|
||||||
}
|
}
|
||||||
else {
|
#if current app version is unknown
|
||||||
#Send failed updated app notification
|
elseif($($app.Version) -eq "Unknown"){
|
||||||
Write-Log "$($app.Name) update failed." "Red"
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
||||||
|
}
|
||||||
#Send Notif
|
#if app is in "excluded list"
|
||||||
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
else{
|
||||||
$Message = $NotifLocale.local.outputs.output[4].message
|
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
|
||||||
$MessageType = "error"
|
|
||||||
$Balise = $($app.Name)
|
|
||||||
Start-NotifTask $Title $Message $MessageType $Balise
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#if current app version is unknown
|
|
||||||
elseif($($app.Version) -eq "Unknown"){
|
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
|
||||||
}
|
}
|
||||||
#if app is in "excluded list"
|
}
|
||||||
else{
|
#If Black List
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
else{
|
||||||
|
#For each app, notify and update
|
||||||
|
foreach ($app in $outdated){
|
||||||
|
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
||||||
|
Update-App $app
|
||||||
|
}
|
||||||
|
#if current app version is unknown
|
||||||
|
elseif($($app.Version) -eq "Unknown"){
|
||||||
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
||||||
|
}
|
||||||
|
#if app is in "excluded list"
|
||||||
|
else{
|
||||||
|
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
@echo off
|
@echo off
|
||||||
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Silent'" -Verb RunAs
|
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UseWhiteList -Silent'" -Verb RunAs
|
||||||
|
|
Loading…
Reference in New Issue