Update megalinter and rename Write-Log function to Write-ToLog

pull/311/head
Fabian Seitz 2023-04-01 16:08:52 +02:00
parent c23f3d6883
commit 1f4bb8bcd6
13 changed files with 130 additions and 127 deletions

View File

@ -11,6 +11,9 @@
'PSPossibleIncorrectComparisonWithNull', 'PSPossibleIncorrectComparisonWithNull',
'PSAvoidTrailingWhitespace', 'PSAvoidTrailingWhitespace',
'PSUseApprovedVerbs', 'PSUseApprovedVerbs',
'PSAvoidUsingWMICmdlet' 'PSAvoidUsingWMICmdlet',
'PSReviewUnusedParameter',
'PSUseDeclaredVarsMoreThanAssignment',
'PSUseShouldProcessForStateChangingFunctions'
) )
} }

View File

@ -45,7 +45,7 @@ jobs:
env: env:
# All available variables are described in documentation # All available variables are described in documentation
# https://megalinter.github.io/configuration/ # https://megalinter.github.io/configuration/
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPELL_CSPELL_CONFIG_FILE: .github/cspell.json SPELL_CSPELL_CONFIG_FILE: .github/cspell.json
POWERSHELL_POWERSHELL_CONFIG_FILE: .github/.powershell-psscriptanalyzer.psd1 POWERSHELL_POWERSHELL_CONFIG_FILE: .github/.powershell-psscriptanalyzer.psd1

View File

@ -19,17 +19,17 @@ $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Cur
#Log running context and more... #Log running context and more...
if ($IsSystem) { if ($IsSystem) {
Write-Log "Running in System context" Write-ToLog "Running in System context"
#Get and set Domain/Local Policies (GPO) #Get and set Domain/Local Policies (GPO)
$ActivateGPOManagement, $ChangedSettings = Get-Policies $ActivateGPOManagement, $ChangedSettings = Get-Policies
if ($ActivateGPOManagement) { if ($ActivateGPOManagement) {
Write-Log "Activated WAU GPO Management detected, comparing..." Write-ToLog "Activated WAU GPO Management detected, comparing..."
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) { if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) {
Write-Log "Changed settings detected and applied" "Yellow" Write-ToLog "Changed settings detected and applied" "Yellow"
} }
else { else {
Write-Log "No Changed settings detected" "Yellow" Write-ToLog "No Changed settings detected" "Yellow"
} }
} }
@ -54,7 +54,7 @@ if ($IsSystem) {
#LogRotation if System #LogRotation if System
$LogRotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize $LogRotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize
if ($LogRotate -eq $False) { if ($LogRotate -eq $False) {
Write-Log "An Exception occured during Log Rotation..." Write-ToLog "An Exception occured during Log Rotation..."
} }
#Run post update actions if necessary if run as System #Run post update actions if necessary if run as System
@ -66,12 +66,12 @@ if ($IsSystem) {
Add-ScopeMachine $SettingsPath Add-ScopeMachine $SettingsPath
} }
else { else {
Write-Log "Running in User context" Write-ToLog "Running in User context"
} }
#Get Notif Locale function #Get Notif Locale function
$LocaleDisplayName = Get-NotifLocale $LocaleDisplayName = Get-NotifLocale
Write-Log "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan" Write-ToLog "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" "Cyan"
#Check network connectivity #Check network connectivity
if (Test-Network) { if (Test-Network) {
@ -81,26 +81,26 @@ if (Test-Network) {
if ($TestWinget) { if ($TestWinget) {
#Get Current Version #Get Current Version
$WAUCurrentVersion = $WAUConfig.DisplayVersion $WAUCurrentVersion = $WAUConfig.DisplayVersion
Write-Log "WAU current version: $WAUCurrentVersion" Write-ToLog "WAU current version: $WAUCurrentVersion"
if ($IsSystem) { if ($IsSystem) {
#Check if WAU update feature is enabled or not if run as System #Check if WAU update feature is enabled or not if run as System
$WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate $WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate
#If yes then check WAU update if run as System #If yes then check WAU update if run as System
if ($WAUDisableAutoUpdate -eq 1) { if ($WAUDisableAutoUpdate -eq 1) {
Write-Log "WAU AutoUpdate is Disabled." "Gray" Write-ToLog "WAU AutoUpdate is Disabled." "Gray"
} }
else { else {
Write-Log "WAU AutoUpdate is Enabled." "Green" Write-ToLog "WAU AutoUpdate is Enabled." "Green"
#Get Available Version #Get Available Version
$WAUAvailableVersion = Get-WAUAvailableVersion $WAUAvailableVersion = Get-WAUAvailableVersion
#Compare #Compare
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) { if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) {
#If new version is available, update it #If new version is available, update it
Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow" Write-ToLog "WAU Available version: $WAUAvailableVersion" "Yellow"
Update-WAU Update-WAU
} }
else { else {
Write-Log "WAU is up to date." "Green" Write-ToLog "WAU is up to date." "Green"
} }
} }
@ -112,35 +112,35 @@ if (Test-Network) {
#Get External ListPath if run as System #Get External ListPath if run as System
if ($WAUConfig.WAU_ListPath) { if ($WAUConfig.WAU_ListPath) {
$ListPathClean = $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/")) $ListPathClean = $($WAUConfig.WAU_ListPath.TrimEnd(" ", "\", "/"))
Write-Log "WAU uses External Lists from: $ListPathClean" Write-ToLog "WAU uses External Lists from: $ListPathClean"
if ($ListPathClean -ne "GPO") { if ($ListPathClean -ne "GPO") {
$NewList = Test-ListPath $ListPathClean $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") $NewList = Test-ListPath $ListPathClean $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\")
if ($ReachNoPath) { if ($ReachNoPath) {
Write-Log "Couldn't reach/find/compare/copy from $ListPathClean..." "Red" Write-ToLog "Couldn't reach/find/compare/copy from $ListPathClean..." "Red"
if ($ListPathClean -notlike "http*") { if ($ListPathClean -notlike "http*") {
if (Test-Path -Path "$ListPathClean" -PathType Leaf) { if (Test-Path -Path "$ListPathClean" -PathType Leaf) {
Write-Log "PATH must end with a Directory, not a File..." "Red" Write-ToLog "PATH must end with a Directory, not a File..." "Red"
} }
} }
else { else {
if ($ListPathClean -match "_apps.txt") { if ($ListPathClean -match "_apps.txt") {
Write-Log "PATH must end with a Directory, not a File..." "Red" Write-ToLog "PATH must end with a Directory, not a File..." "Red"
} }
} }
$Script:ReachNoPath = $False $Script:ReachNoPath = $False
} }
if ($NewList) { if ($NewList) {
Write-Log "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))" "Yellow" Write-ToLog "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))" "Yellow"
} }
else { else {
if ($WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\included_apps.txt")) { if ($WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\included_apps.txt")) {
Write-Log "List (white) is up to date." "Green" Write-ToLog "List (white) is up to date." "Green"
} }
elseif (!$WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\excluded_apps.txt")) { elseif (!$WAUConfig.WAU_UseWhiteList -and (Test-Path "$WorkingDir\excluded_apps.txt")) {
Write-Log "List (black) is up to date." "Green" Write-ToLog "List (black) is up to date." "Green"
} }
else { else {
Write-Log "Critical: White/Black List doesn't exist, exiting..." "Red" Write-ToLog "Critical: White/Black List doesn't exist, exiting..." "Red"
New-Item "$WorkingDir\logs\error.txt" -Value "White/Black List doesn't exist" -Force New-Item "$WorkingDir\logs\error.txt" -Value "White/Black List doesn't exist" -Force
Exit 1 Exit 1
} }
@ -151,25 +151,25 @@ if (Test-Network) {
#Get External ModsPath if run as System #Get External ModsPath if run as System
if ($WAUConfig.WAU_ModsPath) { if ($WAUConfig.WAU_ModsPath) {
$ModsPathClean = $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/")) $ModsPathClean = $($WAUConfig.WAU_ModsPath.TrimEnd(" ", "\", "/"))
Write-Log "WAU uses External Mods from: $ModsPathClean" Write-ToLog "WAU uses External Mods from: $ModsPathClean"
$NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(" ", "\") $WAUConfig.WAU_AzureBlobSASURL.TrimEnd(" ") $NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(" ", "\") $WAUConfig.WAU_AzureBlobSASURL.TrimEnd(" ")
if ($ReachNoPath) { if ($ReachNoPath) {
Write-Log "Couldn't reach/find/compare/copy from $ModsPathClean..." "Red" Write-ToLog "Couldn't reach/find/compare/copy from $ModsPathClean..." "Red"
$Script:ReachNoPath = $False $Script:ReachNoPath = $False
} }
if ($NewMods -gt 0) { if ($NewMods -gt 0) {
Write-Log "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Yellow" Write-ToLog "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Yellow"
} }
else { else {
if (Test-Path "$WorkingDir\mods\*.ps1") { if (Test-Path "$WorkingDir\mods\*.ps1") {
Write-Log "Mods are up to date." "Green" Write-ToLog "Mods are up to date." "Green"
} }
else { else {
Write-Log "No Mods are implemented..." "Yellow" Write-ToLog "No Mods are implemented..." "Yellow"
} }
} }
if ($DeletedMods -gt 0) { if ($DeletedMods -gt 0) {
Write-Log "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Red" Write-ToLog "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(" ", "\"))\mods" "Red"
} }
} }
} }
@ -180,12 +180,12 @@ if (Test-Network) {
#Get White or Black list #Get White or Black list
if ($WAUConfig.WAU_UseWhiteList -eq 1) { if ($WAUConfig.WAU_UseWhiteList -eq 1) {
Write-Log "WAU uses White List config" Write-ToLog "WAU uses White List config"
$toUpdate = Get-IncludedApps $toUpdate = Get-IncludedApps
$UseWhiteList = $true $UseWhiteList = $true
} }
else { else {
Write-Log "WAU uses Black List config" Write-ToLog "WAU uses Black List config"
$toSkip = Get-ExcludedApps $toSkip = Get-ExcludedApps
} }
@ -194,7 +194,7 @@ if (Test-Network) {
if ($UseWhiteList) { if ($UseWhiteList) {
$WhiteList = $toUpdate.GetUpperBound(0) $WhiteList = $toUpdate.GetUpperBound(0)
if ($null -eq $WhiteList) { if ($null -eq $WhiteList) {
Write-Log "Critical: Whitelist doesn't exist in GPO, exiting..." "Red" Write-ToLog "Critical: Whitelist doesn't exist in GPO, exiting..." "Red"
New-Item "$WorkingDir\logs\error.txt" -Value "Whitelist doesn't exist in GPO" -Force New-Item "$WorkingDir\logs\error.txt" -Value "Whitelist doesn't exist in GPO" -Force
Exit 1 Exit 1
} }
@ -203,7 +203,7 @@ if (Test-Network) {
else { else {
$BlackList = $toSkip.GetUpperBound(0) $BlackList = $toSkip.GetUpperBound(0)
if ($null -eq $BlackList) { if ($null -eq $BlackList) {
Write-Log "Critical: Blacklist doesn't exist in GPO, exiting..." "Red" Write-ToLog "Critical: Blacklist doesn't exist in GPO, exiting..." "Red"
New-Item "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force New-Item "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force
Exit 1 Exit 1
} }
@ -212,12 +212,12 @@ if (Test-Network) {
} }
#Get outdated Winget packages #Get outdated Winget packages
Write-Log "Checking application updates on Winget Repository..." "yellow" Write-ToLog "Checking application updates on Winget Repository..." "yellow"
$outdated = Get-WingetOutdatedApps $outdated = Get-WingetOutdatedApps
#If something unusual happened #If something unusual happened
if ($outdated -like "An unusual*") { if ($outdated -like "An unusual*") {
Write-Log "$outdated" "cyan" Write-ToLog "$outdated" "cyan"
$outdated = $False $outdated = $False
} }
@ -236,7 +236,7 @@ if (Test-Network) {
#Trick under user context when -BypassListForUsers is used #Trick under user context when -BypassListForUsers is used
if ($IsSystem -eq $false -and $WAUConfig.WAU_BypassListForUsers -eq $true) { if ($IsSystem -eq $false -and $WAUConfig.WAU_BypassListForUsers -eq $true) {
Write-Log "Bypass system list in user context is Enabled." Write-ToLog "Bypass system list in user context is Enabled."
$UseWhiteList = $false $UseWhiteList = $false
$toSkip = $null $toSkip = $null
} }
@ -250,11 +250,11 @@ if (Test-Network) {
} }
#if current app version is unknown #if current app version is unknown
elseif ($($app.Version) -eq "Unknown") { elseif ($($app.Version) -eq "Unknown") {
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray" Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
} }
#if app is in "excluded list" #if app is in "excluded list"
else { else {
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray" Write-ToLog "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
} }
} }
} }
@ -267,22 +267,22 @@ if (Test-Network) {
} }
#if current app version is unknown #if current app version is unknown
elseif ($($app.Version) -eq "Unknown") { elseif ($($app.Version) -eq "Unknown") {
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray" Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
} }
#if app is in "excluded list" #if app is in "excluded list"
else { else {
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray" Write-ToLog "$($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-ToLog "$InstallOK apps updated ! No more update." "Green"
} }
} }
if ($InstallOK -eq 0 -or !$InstallOK) { if ($InstallOK -eq 0 -or !$InstallOK) {
Write-Log "No new update." "Green" Write-ToLog "No new update." "Green"
} }
#Check if any user is logged on if System and run User task (if installed) #Check if any user is logged on if System and run User task (if installed)
@ -290,7 +290,7 @@ if (Test-Network) {
#User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status #User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status
$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue) $explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
If ($explorerprocesses.Count -eq 0) { If ($explorerprocesses.Count -eq 0) {
Write-Log "No explorer process found / Nobody interactively logged on..." Write-ToLog "No explorer process found / Nobody interactively logged on..."
} }
Else { Else {
#Run WAU in user context if the user task exist #Run WAU in user context if the user task exist
@ -298,28 +298,28 @@ if (Test-Network) {
if ($UserScheduledTask) { if ($UserScheduledTask) {
#Get Winget system apps to excape them befor running user context #Get Winget system apps to excape them befor running user context
Write-Log "User logged on, get a list of installed Winget apps in System context..." Write-ToLog "User logged on, get a list of installed Winget apps in System context..."
Get-WingetSystemApps Get-WingetSystemApps
#Run user context scheduled task #Run user context scheduled task
Write-Log "Starting WAU in User context" Write-ToLog "Starting WAU in User context"
Start-ScheduledTask $UserScheduledTask.TaskName -ErrorAction SilentlyContinue Start-ScheduledTask $UserScheduledTask.TaskName -ErrorAction SilentlyContinue
Exit 0 Exit 0
} }
elseif (!$UserScheduledTask) { elseif (!$UserScheduledTask) {
Write-Log "User context execution not installed..." Write-ToLog "User context execution not installed..."
} }
} }
} }
} }
else { else {
Write-Log "Critical: Winget not installed or detected, exiting..." "red" Write-ToLog "Critical: Winget not installed or detected, exiting..." "red"
New-Item "$WorkingDir\logs\error.txt" -Value "Winget not installed or detected" -Force New-Item "$WorkingDir\logs\error.txt" -Value "Winget not installed or detected" -Force
Write-Log "End of process!" "Cyan" Write-ToLog "End of process!" "Cyan"
Exit 1 Exit 1
} }
} }
#End #End
Write-Log "End of process!" "Cyan" Write-ToLog "End of process!" "Cyan"
Start-Sleep 3 Start-Sleep 3

View File

@ -13,17 +13,17 @@ Function Get-AZCopy ($WingetUpdatePath) {
if (Test-Path -Path "$WingetUpdatePath\azcopy.exe" -PathType Leaf) { if (Test-Path -Path "$WingetUpdatePath\azcopy.exe" -PathType Leaf) {
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v $AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-Log "AZCopy version $AZCopyCurrentVersion found" Write-ToLog "AZCopy version $AZCopyCurrentVersion found"
} }
else { else {
Write-Log "AZCopy not already installed" Write-ToLog "AZCopy not already installed"
$AZCopyCurrentVersion = "0.0.0" $AZCopyCurrentVersion = "0.0.0"
} }
if (([version] $AZCopyCurrentVersion) -lt ([version] $AZCopyLatestVersion)) { if (([version] $AZCopyCurrentVersion) -lt ([version] $AZCopyLatestVersion)) {
Write-Log "Installing version $AZCopyLatestVersion of AZCopy" Write-ToLog "Installing version $AZCopyLatestVersion of AZCopy"
Invoke-WebRequest -Uri $AZCopyLink -UseBasicParsing -OutFile "$WingetUpdatePath\azcopyv10.zip" Invoke-WebRequest -Uri $AZCopyLink -UseBasicParsing -OutFile "$WingetUpdatePath\azcopyv10.zip"
Write-Log "Extracting AZCopy zip file" Write-ToLog "Extracting AZCopy zip file"
Expand-archive -Path "$WingetUpdatePath\azcopyv10.zip" -Destinationpath "$WingetUpdatePath" -Force Expand-archive -Path "$WingetUpdatePath\azcopyv10.zip" -Destinationpath "$WingetUpdatePath" -Force
@ -36,15 +36,15 @@ Function Get-AZCopy ($WingetUpdatePath) {
$AZCopyEXEPath = $AZCopyPathSearch $AZCopyEXEPath = $AZCopyPathSearch
} }
Write-Log "Copying 'azcopy.exe' to main folder" Write-ToLog "Copying 'azcopy.exe' to main folder"
Copy-Item "$AZCopyEXEPath\azcopy.exe" -Destination "$WingetUpdatePath\" Copy-Item "$AZCopyEXEPath\azcopy.exe" -Destination "$WingetUpdatePath\"
Write-Log "Removing temporary AZCopy files" Write-ToLog "Removing temporary AZCopy files"
Remove-Item -Path $AZCopyEXEPath -Recurse Remove-Item -Path $AZCopyEXEPath -Recurse
Remove-Item -Path "$WingetUpdatePath\azcopyv10.zip" Remove-Item -Path "$WingetUpdatePath\azcopyv10.zip"
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v $AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-Log "AZCopy version $AZCopyCurrentVersion installed" Write-ToLog "AZCopy version $AZCopyCurrentVersion installed"
} }
} }

View File

@ -6,7 +6,7 @@ function Get-WAUAvailableVersion {
if ($WAUConfig.WAU_UpdatePrerelease -eq 1) { if ($WAUConfig.WAU_UpdatePrerelease -eq 1) {
#Log #Log
Write-log "WAU AutoUpdate Pre-release versions is Enabled" "Cyan" Write-ToLog "WAU AutoUpdate Pre-release versions is Enabled" "Cyan"
#Get latest pre-release info #Get latest pre-release info
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases'

View File

@ -21,7 +21,7 @@ Function Get-WingetCmd {
$Script:Winget = "$WingetPath\winget.exe" $Script:Winget = "$WingetPath\winget.exe"
} }
else { else {
Write-Log "Winget not installed or detected !" "Red" Write-ToLog "Winget not installed or detected !" "Red"
return $false return $false
} }
@ -30,7 +30,7 @@ Function Get-WingetCmd {
#Log Winget installed version #Log Winget installed version
$WingetVer = & $Winget --version $WingetVer = & $Winget --version
Write-Log "Winget Version: $WingetVer" Write-ToLog "Winget Version: $WingetVer"
return $true return $true

View File

@ -1,4 +1,4 @@
#Function to rotate the logs #Function to rotate the logs
function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) {
<# <#
@ -73,17 +73,17 @@ function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) {
#Log Header #Log Header
$Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
$Log | out-file -filepath $LogFile -Append $Log | out-file -filepath $LogFile -Append
Write-Log "Running in System context" Write-ToLog "Running in System context"
if ($ActivateGPOManagement) { if ($ActivateGPOManagement) {
Write-Log "Activated WAU GPO Management detected, comparing..." Write-ToLog "Activated WAU GPO Management detected, comparing..."
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) { if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) {
Write-Log "Changed settings detected and applied" "Yellow" Write-ToLog "Changed settings detected and applied" "Yellow"
} }
else { else {
Write-Log "No Changed settings detected" "Yellow" Write-ToLog "No Changed settings detected" "Yellow"
} }
} }
Write-Log "Max Log Size reached: $MaxLogSize bytes - Rotated Logs" Write-ToLog "Max Log Size reached: $MaxLogSize bytes - Rotated Logs"
Return $True Return $True
} }

View File

@ -3,15 +3,15 @@
function Invoke-PostUpdateActions { function Invoke-PostUpdateActions {
#log #log
Write-Log "Running Post Update actions:" "yellow" Write-ToLog "Running Post Update actions:" "yellow"
#Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink #Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink
if ((Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and !(Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log")) { if ((Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and !(Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log")) {
Write-log "-> Creating SymLink for log file in Intune Management Extension log folder" "yellow" Write-ToLog "-> Creating SymLink for log file in Intune Management Extension log folder" "yellow"
New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null
} }
Write-Log "-> Checking prerequisites..." "yellow" Write-ToLog "-> Checking prerequisites..." "yellow"
#Check if Visual C++ 2019 or 2022 installed #Check if Visual C++ 2019 or 2022 installed
$Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*" $Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*"
@ -27,25 +27,25 @@ function Invoke-PostUpdateActions {
else { else {
$OSArch = "x86" $OSArch = "x86"
} }
Write-Log "-> Downloading VC_redist.$OSArch.exe..." Write-ToLog "-> Downloading VC_redist.$OSArch.exe..."
$SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe" $SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
$Installer = "$($WAUConfig.InstallLocation)\VC_redist.$OSArch.exe" $Installer = "$($WAUConfig.InstallLocation)\VC_redist.$OSArch.exe"
$ProgressPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force) Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force)
Write-Log "-> Installing VC_redist.$OSArch.exe..." Write-ToLog "-> Installing VC_redist.$OSArch.exe..."
Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait
Remove-Item $Installer -ErrorAction Ignore Remove-Item $Installer -ErrorAction Ignore
Write-Log "-> MS Visual C++ 2015-2022 installed successfully" "green" Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully" "green"
} }
catch { catch {
Write-Log "-> MS Visual C++ 2015-2022 installation failed." "red" Write-ToLog "-> MS Visual C++ 2015-2022 installation failed." "red"
} }
} }
else { else {
Write-Log "-> Prerequisites checked. OK" "green" Write-ToLog "-> Prerequisites checked. OK" "green"
} }
Write-Log "-> Checking if Winget is installed/up to date" "yellow" Write-ToLog "-> Checking if Winget is installed/up to date" "yellow"
#Check Package Install #Check Package Install
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" }
@ -53,25 +53,25 @@ function Invoke-PostUpdateActions {
#Current: v1.4.10173 = 1.19.10173.0 = 2023.118.406.0 #Current: v1.4.10173 = 1.19.10173.0 = 2023.118.406.0
If ([Version]$TestWinGet.Version -ge "2023.118.406.0") { If ([Version]$TestWinGet.Version -ge "2023.118.406.0") {
Write-Log "-> WinGet is Installed/up to date" "green" Write-ToLog "-> WinGet is Installed/up to date" "green"
} }
Else { Else {
#Download WinGet MSIXBundle #Download WinGet MSIXBundle
Write-Log "-> Not installed/up to date. Downloading WinGet..." Write-ToLog "-> Not installed/up to date. Downloading WinGet..."
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.4.10173/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.4.10173/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient = New-Object System.Net.WebClient $WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") $WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
#Install WinGet MSIXBundle #Install WinGet MSIXBundle
try { try {
Write-Log "-> Installing Winget MSIXBundle for App Installer..." Write-ToLog "-> Installing Winget MSIXBundle for App Installer..."
Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
Write-Log "-> Installed Winget MSIXBundle for App Installer" "green" Write-ToLog "-> Installed Winget MSIXBundle for App Installer" "green"
} }
catch { catch {
Write-Log "-> Failed to intall Winget MSIXBundle for App Installer..." "red" Write-ToLog "-> Failed to intall Winget MSIXBundle for App Installer..." "red"
} }
#Remove WinGet MSIXBundle #Remove WinGet MSIXBundle
@ -87,7 +87,7 @@ function Invoke-PostUpdateActions {
& $WingetPath source reset --force & $WingetPath source reset --force
#log #log
Write-Log "-> Winget sources reseted." "green" Write-ToLog "-> Winget sources reseted." "green"
} }
#Create WAU Regkey if not present #Create WAU Regkey if not present
@ -106,7 +106,7 @@ function Invoke-PostUpdateActions {
New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force
#log #log
Write-Log "-> $regPath created." "green" Write-ToLog "-> $regPath created." "green"
} }
#Fix Notif where WAU_NotificationLevel is not set #Fix Notif where WAU_NotificationLevel is not set
$regNotif = Get-ItemProperty $regPath -Name WAU_NotificationLevel -ErrorAction SilentlyContinue $regNotif = Get-ItemProperty $regPath -Name WAU_NotificationLevel -ErrorAction SilentlyContinue
@ -114,7 +114,7 @@ function Invoke-PostUpdateActions {
New-ItemProperty $regPath -Name WAU_NotificationLevel -Value Full -Force New-ItemProperty $regPath -Name WAU_NotificationLevel -Value Full -Force
#log #log
Write-Log "-> Notification level setting was missing. Fixed with 'Full' option." Write-ToLog "-> Notification level setting was missing. Fixed with 'Full' option."
} }
#Set WAU_MaxLogFiles/WAU_MaxLogSize if not set #Set WAU_MaxLogFiles/WAU_MaxLogSize if not set
@ -124,7 +124,7 @@ function Invoke-PostUpdateActions {
New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null
#log #log
Write-Log "-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB)." Write-ToLog "-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB)."
} }
#Set WAU_ListPath if not set #Set WAU_ListPath if not set
@ -133,7 +133,7 @@ function Invoke-PostUpdateActions {
New-ItemProperty $regPath -Name WAU_ListPath -Force | Out-Null New-ItemProperty $regPath -Name WAU_ListPath -Force | Out-Null
#log #log
Write-Log "-> ListPath setting was missing. Fixed with empty string." Write-ToLog "-> ListPath setting was missing. Fixed with empty string."
} }
#Set WAU_ModsPath if not set #Set WAU_ModsPath if not set
@ -142,20 +142,20 @@ function Invoke-PostUpdateActions {
New-ItemProperty $regPath -Name WAU_ModsPath -Force | Out-Null New-ItemProperty $regPath -Name WAU_ModsPath -Force | Out-Null
#log #log
Write-Log "-> ModsPath setting was missing. Fixed with empty string." Write-ToLog "-> ModsPath setting was missing. Fixed with empty string."
} }
#Security check #Security check
Write-Log "-> Checking Mods Directory:" "yellow" Write-ToLog "-> Checking Mods Directory:" "yellow"
$Protected = Invoke-ModsProtect "$($WAUConfig.InstallLocation)\mods" $Protected = Invoke-ModsProtect "$($WAUConfig.InstallLocation)\mods"
if ($Protected -eq $True) { if ($Protected -eq $True) {
Write-Log "-> The mods directory is now secured!" "green" Write-ToLog "-> The mods directory is now secured!" "green"
} }
elseif ($Protected -eq $False) { elseif ($Protected -eq $False) {
Write-Log "-> The mods directory was already secured!" "green" Write-ToLog "-> The mods directory was already secured!" "green"
} }
else { else {
Write-Log "-> Error: The mods directory couldn't be verified as secured!" "red" Write-ToLog "-> Error: The mods directory couldn't be verified as secured!" "red"
} }
#Convert about.xml if exists (previous WAU versions) to reg #Convert about.xml if exists (previous WAU versions) to reg
@ -170,7 +170,7 @@ function Invoke-PostUpdateActions {
Remove-Item $WAUAboutPath -Force -Confirm:$false Remove-Item $WAUAboutPath -Force -Confirm:$false
#log #log
Write-Log "-> $WAUAboutPath converted." "green" Write-ToLog "-> $WAUAboutPath converted." "green"
} }
#Convert config.xml if exists (previous WAU versions) to reg #Convert config.xml if exists (previous WAU versions) to reg
@ -186,7 +186,7 @@ function Invoke-PostUpdateActions {
Remove-Item $WAUConfigPath -Force -Confirm:$false Remove-Item $WAUConfigPath -Force -Confirm:$false
#log #log
Write-Log "-> $WAUConfigPath converted." "green" Write-ToLog "-> $WAUConfigPath converted." "green"
} }
#Remove old functions #Remove old functions
@ -200,7 +200,7 @@ function Invoke-PostUpdateActions {
Remove-Item $FileName -Force -Confirm:$false Remove-Item $FileName -Force -Confirm:$false
#log #log
Write-Log "-> $FileName removed." "green" Write-ToLog "-> $FileName removed." "green"
} }
} }
@ -211,6 +211,6 @@ function Invoke-PostUpdateActions {
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
#log #log
Write-Log "Post Update actions finished" "green" Write-ToLog "Post Update actions finished" "green"
} }

View File

@ -136,12 +136,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
} }
# If Path is Azure Blob # If Path is Azure Blob
elseif ($ExternalMods -like "AzureBlob") { elseif ($ExternalMods -like "AzureBlob") {
Write-Log "Azure Blob Storage set as mod source" Write-ToLog "Azure Blob Storage set as mod source"
Write-Log "Checking AZCopy" Write-ToLog "Checking AZCopy"
Get-AZCopy $WingetUpdatePath Get-AZCopy $WingetUpdatePath
#Safety check to make sure we really do have azcopy.exe and a Blob URL #Safety check to make sure we really do have azcopy.exe and a Blob URL
if ((Test-Path -Path "$WingetUpdatePath\azcopy.exe" -PathType Leaf) -and ($null -ne $AzureBlobSASURL)) { if ((Test-Path -Path "$WingetUpdatePath\azcopy.exe" -PathType Leaf) -and ($null -ne $AzureBlobSASURL)) {
Write-Log "Syncing Blob storage with local storage" Write-ToLog "Syncing Blob storage with local storage"
$AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync "$AzureBlobSASURL" "$LocalMods" --from-to BlobLocal --delete-destination=true $AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync "$AzureBlobSASURL" "$LocalMods" --from-to BlobLocal --delete-destination=true
$AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine) $AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine)
@ -163,12 +163,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) {
} }
if ($AZCopySyncErrorRegex.Match($_).Value) { if ($AZCopySyncErrorRegex.Match($_).Value) {
Write-Log "AZCopy Sync Error! $_" Write-ToLog "AZCopy Sync Error! $_"
} }
} }
} }
else { else {
Write-Log "Error 'azcopy.exe' or SAS Token not found!" Write-ToLog "Error 'azcopy.exe' or SAS Token not found!"
} }
return $ModsUpdated, $DeletedMods return $ModsUpdated, $DeletedMods

View File

@ -9,7 +9,7 @@ function Test-Network {
$ProgressPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue'
#Test connectivity during 30 min then timeout #Test connectivity during 30 min then timeout
Write-Log "Checking internet connection..." "Yellow" Write-ToLog "Checking internet connection..." "Yellow"
While ($timeout -lt 1800) { While ($timeout -lt 1800) {
$URLtoTest = "https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE" $URLtoTest = "https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE"
@ -17,7 +17,7 @@ function Test-Network {
if ($URLcontent -like "*MIT License*") { if ($URLcontent -like "*MIT License*") {
Write-Log "Connected !" "Green" Write-ToLog "Connected !" "Green"
#Check for metered connection #Check for metered connection
[void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime] [void][Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
@ -25,17 +25,17 @@ function Test-Network {
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")) { if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne "Unrestricted")) {
Write-Log "Metered connection detected." "Yellow" Write-ToLog "Metered connection detected." "Yellow"
if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1) { if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1) {
Write-Log "WAU is configured to bypass update checking on metered connection" Write-ToLog "WAU is configured to bypass update checking on metered connection"
return $false return $false
} }
else { else {
Write-Log "WAU is configured to force update checking on metered connection" Write-ToLog "WAU is configured to force update checking on metered connection"
return $true return $true
} }
@ -56,7 +56,7 @@ function Test-Network {
#Send Warning Notif if no connection for 5 min #Send Warning Notif if no connection for 5 min
if ($timeout -eq 300) { if ($timeout -eq 300) {
#Log #Log
Write-Log "Notify 'No connection' sent." "Yellow" Write-ToLog "Notify 'No connection' sent." "Yellow"
#Notif #Notif
$Title = $NotifLocale.local.outputs.output[0].title $Title = $NotifLocale.local.outputs.output[0].title
@ -71,7 +71,7 @@ function Test-Network {
} }
#Send Timeout Notif if no connection for 30 min #Send Timeout Notif if no connection for 30 min
Write-Log "Timeout. No internet connection !" "Red" Write-ToLog "Timeout. No internet connection !" "Red"
#Notif #Notif
$Title = $NotifLocale.local.outputs.output[1].title $Title = $NotifLocale.local.outputs.output[1].title

View File

@ -9,7 +9,7 @@ Function Update-App ($app) {
} }
#Send available update notification #Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan" Write-ToLog "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name) $Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion) $Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info" $MessageType = "info"
@ -20,26 +20,26 @@ Function Update-App ($app) {
$ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id)
#Winget upgrade #Winget upgrade
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" Write-ToLog "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#If PreInstall script exist #If PreInstall script exist
if ($ModsPreInstall) { if ($ModsPreInstall) {
Write-Log "Modifications for $($app.Id) before upgrade are being applied..." "Yellow" Write-ToLog "Modifications for $($app.Id) before upgrade are being applied..." "Yellow"
& "$ModsPreInstall" & "$ModsPreInstall"
} }
#Run Winget Upgrade command #Run Winget Upgrade command
if ($ModsOverride) { if ($ModsOverride) {
Write-Log "-> Running (overriding default): Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride" Write-ToLog "-> Running (overriding default): Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride"
& $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append & $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append
} }
else { else {
Write-Log "-> Running: Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" Write-ToLog "-> Running: Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h"
& $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append & $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
} }
if ($ModsUpgrade) { if ($ModsUpgrade) {
Write-Log "Modifications for $($app.Id) during upgrade are being applied..." "Yellow" Write-ToLog "Modifications for $($app.Id) during upgrade are being applied..." "Yellow"
& "$ModsUpgrade" & "$ModsUpgrade"
} }
@ -53,25 +53,25 @@ Function Update-App ($app) {
#Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
$PendingReboot = Test-PendingReboot $PendingReboot = Test-PendingReboot
if ($PendingReboot -eq $true) { if ($PendingReboot -eq $true) {
Write-Log "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red" Write-ToLog "-> A Pending Reboot lingers and probably prohibited $($app.Name) from upgrading...`n-> ...an install for $($app.Name) is NOT executed!" "Red"
$FailedToUpgrade = $true $FailedToUpgrade = $true
break break
} }
#If app failed to upgrade, run Install command #If app failed to upgrade, run Install command
Write-Log "-> An upgrade for $($app.Name) failed, now trying an install instead..." "Yellow" Write-ToLog "-> An upgrade for $($app.Name) failed, now trying an install instead..." "Yellow"
if ($ModsOverride) { if ($ModsOverride) {
Write-Log "-> Running (overriding default): Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride" Write-ToLog "-> Running (overriding default): Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --override $ModsOverride | Tee-Object -file $LogFile -Append
} }
else { else {
Write-Log "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h" Write-ToLog "-> Running: Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h"
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append & $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
} }
if ($ModsInstall) { if ($ModsInstall) {
Write-Log "Modifications for $($app.Id) during install are being applied..." "Yellow" Write-ToLog "Modifications for $($app.Id) during install are being applied..." "Yellow"
& "$ModsInstall" & "$ModsInstall"
} }
@ -87,18 +87,18 @@ Function Update-App ($app) {
if ($FailedToUpgrade -eq $false) { if ($FailedToUpgrade -eq $false) {
if ($ModsInstalled) { if ($ModsInstalled) {
Write-Log "Modifications for $($app.Id) after upgrade/install are being applied..." "Yellow" Write-ToLog "Modifications for $($app.Id) after upgrade/install are being applied..." "Yellow"
& "$ModsInstalled" & "$ModsInstalled"
} }
} }
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray" Write-ToLog "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Notify installation #Notify installation
if ($FailedToUpgrade -eq $false) { if ($FailedToUpgrade -eq $false) {
#Send success updated app notification #Send success updated app notification
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green" Write-ToLog "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
#Send Notif #Send Notif
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name) $Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
@ -113,7 +113,7 @@ Function Update-App ($app) {
else { else {
#Send failed updated app notification #Send failed updated app notification
Write-Log "$($app.Name) update failed." "Red" Write-ToLog "$($app.Name) update failed." "Red"
#Send Notif #Send Notif
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name) $Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)

View File

@ -19,24 +19,24 @@ function Update-WAU {
New-Item $ZipFile -ItemType File -Force | Out-Null New-Item $ZipFile -ItemType File -Force | Out-Null
#Download the zip #Download the zip
Write-Log "Downloading the GitHub Repository version $WAUAvailableVersion" "Cyan" Write-ToLog "Downloading the GitHub Repository version $WAUAvailableVersion" "Cyan"
Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/archive/refs/tags/v$($WAUAvailableVersion).zip/" -OutFile $ZipFile Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/archive/refs/tags/v$($WAUAvailableVersion).zip/" -OutFile $ZipFile
#Extract Zip File #Extract Zip File
Write-Log "Unzipping the WAU GitHub Repository" "Cyan" Write-ToLog "Unzipping the WAU GitHub Repository" "Cyan"
$location = "$WorkingDir\WAU_update" $location = "$WorkingDir\WAU_update"
Expand-Archive -Path $ZipFile -DestinationPath $location -Force Expand-Archive -Path $ZipFile -DestinationPath $location -Force
Get-ChildItem -Path $location -Recurse | Unblock-File Get-ChildItem -Path $location -Recurse | Unblock-File
#Update scritps #Update scritps
Write-Log "Updating WAU" "Yellow" Write-ToLog "Updating WAU" "Yellow"
$TempPath = (Resolve-Path "$location\*\Winget-AutoUpdate\")[0].Path $TempPath = (Resolve-Path "$location\*\Winget-AutoUpdate\")[0].Path
if ($TempPath) { if ($TempPath) {
Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
} }
#Remove update zip file and update temp folder #Remove update zip file and update temp folder
Write-Log "Done. Cleaning temp files" "Cyan" Write-ToLog "Done. Cleaning temp files" "Cyan"
Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue
Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
@ -49,14 +49,14 @@ function Update-WAU {
$WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 1 -Force $WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 1 -Force
#Send success Notif #Send success Notif
Write-Log "WAU Update completed." "Green" Write-ToLog "WAU Update completed." "Green"
$Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate" $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion
$MessageType = "success" $MessageType = "success"
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
#Rerun with newer version #Rerun with newer version
Write-Log "Re-run WAU" Write-ToLog "Re-run WAU"
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`"" Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`""
exit exit
@ -70,7 +70,7 @@ function Update-WAU {
$Message = $NotifLocale.local.outputs.output[4].message $Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error" $MessageType = "error"
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
Write-Log "WAU Update failed" "Red" Write-ToLog "WAU Update failed" "Red"
} }

View File

@ -1,6 +1,6 @@
#Write to Log Function #Write to Log Function
function Write-Log ($LogMsg, $LogColor = "White") { function Write-ToLog ($LogMsg, $LogColor = "White") {
#Get log #Get log
$Log = "$(Get-Date -UFormat "%T") - $LogMsg" $Log = "$(Get-Date -UFormat "%T") - $LogMsg"