2022-03-14 13:55:02 +00:00
|
|
|
|
<# LOAD FUNCTIONS #>
|
2022-02-14 16:28:22 +00:00
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
|
#Get Working Dir
|
|
|
|
|
$Script:WorkingDir = $PSScriptRoot
|
|
|
|
|
#Get Functions
|
2022-06-10 08:26:41 +00:00
|
|
|
|
Get-ChildItem "$WorkingDir\functions" | ForEach-Object { . $_.FullName }
|
2022-02-14 16:28:22 +00:00
|
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
|
|
2022-02-14 16:28:22 +00:00
|
|
|
|
<# MAIN #>
|
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
|
#Run log initialisation function
|
|
|
|
|
Start-Init
|
|
|
|
|
|
2022-05-22 22:26:00 +00:00
|
|
|
|
#Get WAU Configurations
|
|
|
|
|
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
|
|
|
|
|
2022-05-22 22:39:57 +00:00
|
|
|
|
#Run post update actions if necessary
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) {
|
2022-05-22 22:35:33 +00:00
|
|
|
|
Invoke-PostUpdateActions
|
2022-05-22 22:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 12:19:41 +00:00
|
|
|
|
#Run Scope Machine funtion if run as system
|
|
|
|
|
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
|
2022-08-12 07:19:49 +00:00
|
|
|
|
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
|
2022-05-08 12:19:41 +00:00
|
|
|
|
Add-ScopeMachine $SettingsPath
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
|
#Get Notif Locale function
|
2022-03-22 13:39:01 +00:00
|
|
|
|
Get-NotifLocale
|
2022-02-14 16:28:22 +00:00
|
|
|
|
|
|
|
|
|
#Check network connectivity
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if (Test-Network) {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
#Check if Winget is installed and get Winget cmd
|
2022-04-13 08:50:24 +00:00
|
|
|
|
$TestWinget = Get-WingetCmd
|
2022-04-13 16:50:06 +00:00
|
|
|
|
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($TestWinget) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Get Current Version
|
2022-05-22 13:27:45 +00:00
|
|
|
|
$WAUCurrentVersion = $WAUConfig.DisplayVersion
|
|
|
|
|
Write-Log "WAU current version: $WAUCurrentVersion"
|
|
|
|
|
#Check if WAU update feature is enabled or not
|
|
|
|
|
$WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#If yes then check WAU update
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($WAUDisableAutoUpdate -eq 1) {
|
2022-05-22 13:27:45 +00:00
|
|
|
|
Write-Log "WAU AutoUpdate is Disabled." "Grey"
|
|
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-05-22 13:27:45 +00:00
|
|
|
|
Write-Log "WAU AutoUpdate is Enabled." "Green"
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Get Available Version
|
2022-05-22 13:27:45 +00:00
|
|
|
|
$WAUAvailableVersion = Get-WAUAvailableVersion
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Compare
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#If new version is available, update it
|
|
|
|
|
Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow"
|
|
|
|
|
Update-WAU
|
|
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "WAU is up to date." "Green"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 19:33:46 +00:00
|
|
|
|
#Get External ListPath
|
|
|
|
|
if ($WAUConfig.ListPath) {
|
2022-09-25 14:54:58 +00:00
|
|
|
|
Write-Log "WAU uses External Lists from $WAUConfig.ListPath"
|
2022-09-20 19:33:46 +00:00
|
|
|
|
$NewList = Test-ListPath $WAUConfig.ListPath $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation
|
|
|
|
|
if ($NewList) {
|
|
|
|
|
Write-Log "Newer List downloaded to local path"
|
|
|
|
|
}
|
2022-09-25 14:54:58 +00:00
|
|
|
|
else {
|
|
|
|
|
Write-Log "No newer List detected"
|
|
|
|
|
}
|
2022-09-20 19:33:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Get White or Black list
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
|
2022-04-24 08:51:51 +00:00
|
|
|
|
Write-Log "WAU uses White List config"
|
2022-04-13 08:50:24 +00:00
|
|
|
|
$toUpdate = Get-IncludedApps
|
2022-05-22 13:27:45 +00:00
|
|
|
|
$UseWhiteList = $true
|
2022-03-22 13:39:01 +00:00
|
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-04-24 08:51:51 +00:00
|
|
|
|
Write-Log "WAU uses Black List config"
|
2022-04-13 08:50:24 +00:00
|
|
|
|
$toSkip = Get-ExcludedApps
|
2022-03-26 21:48:56 +00:00
|
|
|
|
}
|
2022-02-14 16:28:22 +00:00
|
|
|
|
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Get outdated Winget packages
|
|
|
|
|
$outdated = Get-WingetOutdatedApps
|
2022-04-05 13:17:18 +00:00
|
|
|
|
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#Log list of app to update
|
2022-06-10 08:26:41 +00:00
|
|
|
|
foreach ($app in $outdated) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#List available updates
|
2022-05-23 07:35:49 +00:00
|
|
|
|
$Log = "-> Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
|
2022-04-13 08:50:24 +00:00
|
|
|
|
$Log | Write-host
|
|
|
|
|
$Log | out-file -filepath $LogFile -Append
|
2022-02-21 13:26:30 +00:00
|
|
|
|
}
|
2022-04-13 08:50:24 +00:00
|
|
|
|
|
|
|
|
|
#Count good update installations
|
|
|
|
|
$Script:InstallOK = 0
|
|
|
|
|
|
|
|
|
|
#If White List
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($UseWhiteList) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#For each app, notify and update
|
2022-06-10 08:26:41 +00:00
|
|
|
|
foreach ($app in $outdated) {
|
|
|
|
|
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Update-App $app
|
|
|
|
|
}
|
|
|
|
|
#if current app version is unknown
|
2022-06-10 08:26:41 +00:00
|
|
|
|
elseif ($($app.Version) -eq "Unknown") {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
|
|
|
|
}
|
|
|
|
|
#if app is in "excluded list"
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
|
|
|
|
|
}
|
2022-04-05 13:17:18 +00:00
|
|
|
|
}
|
2022-04-13 08:50:24 +00:00
|
|
|
|
}
|
2022-05-22 13:27:45 +00:00
|
|
|
|
#If Black List or default
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
#For each app, notify and update
|
2022-06-10 08:26:41 +00:00
|
|
|
|
foreach ($app in $outdated) {
|
|
|
|
|
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Update-App $app
|
|
|
|
|
}
|
|
|
|
|
#if current app version is unknown
|
2022-06-10 08:26:41 +00:00
|
|
|
|
elseif ($($app.Version) -eq "Unknown") {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
|
|
|
|
}
|
|
|
|
|
#if app is in "excluded list"
|
2022-06-10 08:26:41 +00:00
|
|
|
|
else {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
|
|
|
|
}
|
2022-04-05 13:17:18 +00:00
|
|
|
|
}
|
2022-02-14 16:28:22 +00:00
|
|
|
|
}
|
2022-04-13 08:50:24 +00:00
|
|
|
|
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($InstallOK -gt 0) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
|
|
|
|
}
|
2022-06-10 08:26:41 +00:00
|
|
|
|
if ($InstallOK -eq 0) {
|
2022-04-13 08:50:24 +00:00
|
|
|
|
Write-Log "No new update." "Green"
|
|
|
|
|
}
|
2022-02-14 16:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 22:56:44 +00:00
|
|
|
|
|
|
|
|
|
#Run WAU in user context if currently as system
|
|
|
|
|
if ($currentPrincipal -eq $false) {
|
|
|
|
|
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 16:28:22 +00:00
|
|
|
|
#End
|
|
|
|
|
Write-Log "End of process!" "Cyan"
|
2022-04-13 16:50:06 +00:00
|
|
|
|
Start-Sleep 3
|