commit
e5230a8923
|
@ -19,11 +19,18 @@ Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate i
|
||||||
.PARAMETER DisableWAUAutoUpdate
|
.PARAMETER DisableWAUAutoUpdate
|
||||||
Disable Winget-AutoUpdate update checking. By default, WAU auto update if new version is available on Github.
|
Disable Winget-AutoUpdate update checking. By default, WAU auto update if new version is available on Github.
|
||||||
|
|
||||||
|
.PARAMETER UseWhiteList
|
||||||
|
Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt"
|
||||||
|
|
||||||
.PARAMETER Uninstall
|
.PARAMETER Uninstall
|
||||||
Remove scheduled tasks and scripts.
|
Remove scheduled tasks and scripts.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\winget-install-and-update.ps1 -Silent -DoNotUpdate
|
.\winget-install-and-update.ps1 -Silent -DoNotUpdate
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\winget-install-and-update.ps1 -Silent -UseWhiteList
|
||||||
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
@ -32,7 +39,8 @@ param(
|
||||||
[Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
|
[Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
|
||||||
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false,
|
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false,
|
||||||
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
|
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
|
||||||
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false
|
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false,
|
||||||
|
[Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,20 +94,24 @@ function Install-Prerequisites{
|
||||||
|
|
||||||
function Install-WingetAutoUpdate{
|
function Install-WingetAutoUpdate{
|
||||||
try{
|
try{
|
||||||
#Check if previous version location exists and delete
|
|
||||||
$OldWingetUpdatePath = $WingetUpdatePath.Replace("\Winget-AutoUpdate","\winget-update")
|
|
||||||
if (Test-Path ($OldWingetUpdatePath)){
|
|
||||||
Remove-Item $OldWingetUpdatePath -Force -Recurse
|
|
||||||
}
|
|
||||||
Get-ScheduledTask -TaskName "Winget Update" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
|
|
||||||
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
|
|
||||||
|
|
||||||
#Copy files to location
|
#Copy files to location
|
||||||
if (!(Test-Path $WingetUpdatePath)){
|
if (!(Test-Path $WingetUpdatePath)){
|
||||||
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
|
||||||
|
if ($UseWhiteList){
|
||||||
|
if (Test-Path "$PSScriptRoot\included_apps.txt"){
|
||||||
|
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
# Set dummy regkeys for notification name and icon
|
# Set dummy regkeys for notification name and icon
|
||||||
& reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v DisplayName /t REG_EXPAND_SZ /d "Application Update" /f | Out-Null
|
& reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v DisplayName /t REG_EXPAND_SZ /d "Application Update" /f | Out-Null
|
||||||
|
@ -130,6 +142,7 @@ function Install-WingetAutoUpdate{
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<app>
|
<app>
|
||||||
<WAUautoupdate>$(!($DisableWAUAutoUpdate))</WAUautoupdate>
|
<WAUautoupdate>$(!($DisableWAUAutoUpdate))</WAUautoupdate>
|
||||||
|
<UseWAUWhiteList>$UseWhiteList</UseWAUWhiteList>
|
||||||
</app>
|
</app>
|
||||||
"@
|
"@
|
||||||
$ConfigXML.Save("$WingetUpdatePath\config\config.xml")
|
$ConfigXML.Save("$WingetUpdatePath\config\config.xml")
|
||||||
|
|
|
@ -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
|
||||||
|
Get-WAUConfig
|
||||||
|
if ($UseWhiteList){
|
||||||
|
$toUpdate = Get-IncludedApps
|
||||||
|
}
|
||||||
|
else{
|
||||||
$toSkip = Get-ExcludedApps
|
$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,69 +57,31 @@ if (Test-Network){
|
||||||
}
|
}
|
||||||
|
|
||||||
#Count good update installations
|
#Count good update installations
|
||||||
$InstallOK = 0
|
$Script:InstallOK = 0
|
||||||
|
|
||||||
|
#If White List
|
||||||
|
if ($UseWhiteList){
|
||||||
|
#For each app, notify and update
|
||||||
|
foreach ($app in $outdated){
|
||||||
|
if (($toUpdate -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 not in the included app list" "Gray"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#If Black List
|
||||||
|
else{
|
||||||
#For each app, notify and update
|
#For each app, notify and update
|
||||||
foreach ($app in $outdated){
|
foreach ($app in $outdated){
|
||||||
|
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
||||||
|
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
|
|
||||||
& $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 {
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#if current app version is unknown
|
#if current app version is unknown
|
||||||
elseif($($app.Version) -eq "Unknown"){
|
elseif($($app.Version) -eq "Unknown"){
|
||||||
|
@ -124,6 +92,7 @@ if (Test-Network){
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($InstallOK -gt 0){
|
if ($InstallOK -gt 0){
|
||||||
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
||||||
|
|
Loading…
Reference in New Issue