diff --git a/.github/.powershell-psscriptanalyzer.psd1 b/.github/.powershell-psscriptanalyzer.psd1 index 6128b5c..21f77be 100644 --- a/.github/.powershell-psscriptanalyzer.psd1 +++ b/.github/.powershell-psscriptanalyzer.psd1 @@ -11,6 +11,9 @@ 'PSPossibleIncorrectComparisonWithNull', 'PSAvoidTrailingWhitespace', 'PSUseApprovedVerbs', - 'PSAvoidUsingWMICmdlet' + 'PSAvoidUsingWMICmdlet', + 'PSReviewUnusedParameter', + 'PSUseDeclaredVarsMoreThanAssignment', + 'PSUseShouldProcessForStateChangingFunctions' ) } \ No newline at end of file diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml index a26541b..ff9d2c4 100644 --- a/.github/workflows/mega-linter.yml +++ b/.github/workflows/mega-linter.yml @@ -45,7 +45,7 @@ jobs: env: # All available variables are described in documentation # 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 }} SPELL_CSPELL_CONFIG_FILE: .github/cspell.json POWERSHELL_POWERSHELL_CONFIG_FILE: .github/.powershell-psscriptanalyzer.psd1 diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 9bede9d..d8b015b 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -19,17 +19,17 @@ $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Cur #Log running context and more... if ($IsSystem) { - Write-Log "Running in System context" + Write-ToLog "Running in System context" #Get and set Domain/Local Policies (GPO) $ActivateGPOManagement, $ChangedSettings = Get-Policies 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) { - Write-Log "Changed settings detected and applied" "Yellow" + Write-ToLog "Changed settings detected and applied" "Yellow" } else { - Write-Log "No Changed settings detected" "Yellow" + Write-ToLog "No Changed settings detected" "Yellow" } } @@ -54,7 +54,7 @@ if ($IsSystem) { #LogRotation if System $LogRotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize 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 @@ -66,12 +66,12 @@ if ($IsSystem) { Add-ScopeMachine $SettingsPath } else { - Write-Log "Running in User context" + Write-ToLog "Running in User context" } #Get Notif Locale function $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 if (Test-Network) { @@ -81,26 +81,26 @@ if (Test-Network) { if ($TestWinget) { #Get Current Version $WAUCurrentVersion = $WAUConfig.DisplayVersion - Write-Log "WAU current version: $WAUCurrentVersion" + Write-ToLog "WAU current version: $WAUCurrentVersion" if ($IsSystem) { #Check if WAU update feature is enabled or not if run as System $WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate #If yes then check WAU update if run as System if ($WAUDisableAutoUpdate -eq 1) { - Write-Log "WAU AutoUpdate is Disabled." "Gray" + Write-ToLog "WAU AutoUpdate is Disabled." "Gray" } else { - Write-Log "WAU AutoUpdate is Enabled." "Green" + Write-ToLog "WAU AutoUpdate is Enabled." "Green" #Get Available Version $WAUAvailableVersion = Get-WAUAvailableVersion #Compare if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) { #If new version is available, update it - Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow" + Write-ToLog "WAU Available version: $WAUAvailableVersion" "Yellow" Update-WAU } 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 if ($WAUConfig.WAU_ListPath) { $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") { $NewList = Test-ListPath $ListPathClean $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(" ", "\") 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 (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 { 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 } 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 { 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")) { - Write-Log "List (black) is up to date." "Green" + Write-ToLog "List (black) is up to date." "Green" } 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 Exit 1 } @@ -151,25 +151,25 @@ if (Test-Network) { #Get External ModsPath if run as System if ($WAUConfig.WAU_ModsPath) { $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(" ") 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 } 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 { if (Test-Path "$WorkingDir\mods\*.ps1") { - Write-Log "Mods are up to date." "Green" + Write-ToLog "Mods are up to date." "Green" } else { - Write-Log "No Mods are implemented..." "Yellow" + Write-ToLog "No Mods are implemented..." "Yellow" } } 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 if ($WAUConfig.WAU_UseWhiteList -eq 1) { - Write-Log "WAU uses White List config" + Write-ToLog "WAU uses White List config" $toUpdate = Get-IncludedApps $UseWhiteList = $true } else { - Write-Log "WAU uses Black List config" + Write-ToLog "WAU uses Black List config" $toSkip = Get-ExcludedApps } @@ -194,7 +194,7 @@ if (Test-Network) { if ($UseWhiteList) { $WhiteList = $toUpdate.GetUpperBound(0) 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 Exit 1 } @@ -203,7 +203,7 @@ if (Test-Network) { else { $BlackList = $toSkip.GetUpperBound(0) 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 Exit 1 } @@ -212,12 +212,12 @@ if (Test-Network) { } #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 #If something unusual happened if ($outdated -like "An unusual*") { - Write-Log "$outdated" "cyan" + Write-ToLog "$outdated" "cyan" $outdated = $False } @@ -236,7 +236,7 @@ if (Test-Network) { #Trick under user context when -BypassListForUsers is used 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 $toSkip = $null } @@ -250,11 +250,11 @@ if (Test-Network) { } #if current app version is 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" 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 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" 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) { - Write-Log "$InstallOK apps updated ! No more update." "Green" + Write-ToLog "$InstallOK apps updated ! No more update." "Green" } } 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) @@ -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 $explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue) 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 { #Run WAU in user context if the user task exist @@ -298,28 +298,28 @@ if (Test-Network) { if ($UserScheduledTask) { #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 #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 Exit 0 } elseif (!$UserScheduledTask) { - Write-Log "User context execution not installed..." + Write-ToLog "User context execution not installed..." } } } } 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 - Write-Log "End of process!" "Cyan" + Write-ToLog "End of process!" "Cyan" Exit 1 } } #End -Write-Log "End of process!" "Cyan" +Write-ToLog "End of process!" "Cyan" Start-Sleep 3 diff --git a/Winget-AutoUpdate/functions/Get-AZCopy.ps1 b/Winget-AutoUpdate/functions/Get-AZCopy.ps1 index 7926291..e6f7d54 100644 --- a/Winget-AutoUpdate/functions/Get-AZCopy.ps1 +++ b/Winget-AutoUpdate/functions/Get-AZCopy.ps1 @@ -13,17 +13,17 @@ Function Get-AZCopy ($WingetUpdatePath) { if (Test-Path -Path "$WingetUpdatePath\azcopy.exe" -PathType Leaf) { $AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value - Write-Log "AZCopy version $AZCopyCurrentVersion found" + Write-ToLog "AZCopy version $AZCopyCurrentVersion found" } else { - Write-Log "AZCopy not already installed" + Write-ToLog "AZCopy not already installed" $AZCopyCurrentVersion = "0.0.0" } 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" - Write-Log "Extracting AZCopy zip file" + Write-ToLog "Extracting AZCopy zip file" Expand-archive -Path "$WingetUpdatePath\azcopyv10.zip" -Destinationpath "$WingetUpdatePath" -Force @@ -36,15 +36,15 @@ Function Get-AZCopy ($WingetUpdatePath) { $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\" - Write-Log "Removing temporary AZCopy files" + Write-ToLog "Removing temporary AZCopy files" Remove-Item -Path $AZCopyEXEPath -Recurse Remove-Item -Path "$WingetUpdatePath\azcopyv10.zip" $AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value - Write-Log "AZCopy version $AZCopyCurrentVersion installed" + Write-ToLog "AZCopy version $AZCopyCurrentVersion installed" } } \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index 20fd1e9..0d3e535 100644 --- a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -6,7 +6,7 @@ function Get-WAUAvailableVersion { if ($WAUConfig.WAU_UpdatePrerelease -eq 1) { #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 $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' diff --git a/Winget-AutoUpdate/functions/Get-WingetCmd.ps1 b/Winget-AutoUpdate/functions/Get-WingetCmd.ps1 index 7399b1f..3c4ab6d 100644 --- a/Winget-AutoUpdate/functions/Get-WingetCmd.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetCmd.ps1 @@ -21,7 +21,7 @@ Function Get-WingetCmd { $Script:Winget = "$WingetPath\winget.exe" } else { - Write-Log "Winget not installed or detected !" "Red" + Write-ToLog "Winget not installed or detected !" "Red" return $false } @@ -30,7 +30,7 @@ Function Get-WingetCmd { #Log Winget installed version $WingetVer = & $Winget --version - Write-Log "Winget Version: $WingetVer" + Write-ToLog "Winget Version: $WingetVer" return $true diff --git a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 index 8699421..82edf17 100644 --- a/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 @@ -1,4 +1,4 @@ -#Function to rotate the logs +#Function to rotate the logs function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { <# @@ -73,17 +73,17 @@ function Invoke-LogRotation ($LogFile, $MaxLogFiles, $MaxLogSize) { #Log Header $Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################" $Log | out-file -filepath $LogFile -Append - Write-Log "Running in System context" + Write-ToLog "Running in System context" 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) { - Write-Log "Changed settings detected and applied" "Yellow" + Write-ToLog "Changed settings detected and applied" "Yellow" } 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 } diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 1f8b643..e423df7 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -3,15 +3,15 @@ function Invoke-PostUpdateActions { #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 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 } - Write-Log "-> Checking prerequisites..." "yellow" + Write-ToLog "-> Checking prerequisites..." "yellow" #Check if Visual C++ 2019 or 2022 installed $Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*" @@ -27,25 +27,25 @@ function Invoke-PostUpdateActions { else { $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" $Installer = "$($WAUConfig.InstallLocation)\VC_redist.$OSArch.exe" $ProgressPreference = 'SilentlyContinue' 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 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 { - Write-Log "-> MS Visual C++ 2015-2022 installation failed." "red" + Write-ToLog "-> MS Visual C++ 2015-2022 installation failed." "red" } } 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 $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 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 { #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" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") #Install WinGet MSIXBundle 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 - Write-Log "-> Installed Winget MSIXBundle for App Installer" "green" + Write-ToLog "-> Installed Winget MSIXBundle for App Installer" "green" } 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 @@ -87,7 +87,7 @@ function Invoke-PostUpdateActions { & $WingetPath source reset --force #log - Write-Log "-> Winget sources reseted." "green" + Write-ToLog "-> Winget sources reseted." "green" } #Create WAU Regkey if not present @@ -106,7 +106,7 @@ function Invoke-PostUpdateActions { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force #log - Write-Log "-> $regPath created." "green" + Write-ToLog "-> $regPath created." "green" } #Fix Notif where WAU_NotificationLevel is not set $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 #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 @@ -124,7 +124,7 @@ function Invoke-PostUpdateActions { New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null #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 @@ -133,7 +133,7 @@ function Invoke-PostUpdateActions { New-ItemProperty $regPath -Name WAU_ListPath -Force | Out-Null #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 @@ -142,20 +142,20 @@ function Invoke-PostUpdateActions { New-ItemProperty $regPath -Name WAU_ModsPath -Force | Out-Null #log - Write-Log "-> ModsPath setting was missing. Fixed with empty string." + Write-ToLog "-> ModsPath setting was missing. Fixed with empty string." } #Security check - Write-Log "-> Checking Mods Directory:" "yellow" + Write-ToLog "-> Checking Mods Directory:" "yellow" $Protected = Invoke-ModsProtect "$($WAUConfig.InstallLocation)\mods" 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) { - Write-Log "-> The mods directory was already secured!" "green" + Write-ToLog "-> The mods directory was already secured!" "green" } 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 @@ -170,7 +170,7 @@ function Invoke-PostUpdateActions { Remove-Item $WAUAboutPath -Force -Confirm:$false #log - Write-Log "-> $WAUAboutPath converted." "green" + Write-ToLog "-> $WAUAboutPath converted." "green" } #Convert config.xml if exists (previous WAU versions) to reg @@ -186,7 +186,7 @@ function Invoke-PostUpdateActions { Remove-Item $WAUConfigPath -Force -Confirm:$false #log - Write-Log "-> $WAUConfigPath converted." "green" + Write-ToLog "-> $WAUConfigPath converted." "green" } #Remove old functions @@ -200,7 +200,7 @@ function Invoke-PostUpdateActions { Remove-Item $FileName -Force -Confirm:$false #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" #log - Write-Log "Post Update actions finished" "green" + Write-ToLog "Post Update actions finished" "green" } diff --git a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 index 65841f5..9f468b1 100644 --- a/Winget-AutoUpdate/functions/Test-ModsPath.ps1 +++ b/Winget-AutoUpdate/functions/Test-ModsPath.ps1 @@ -136,12 +136,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) { } # If Path is Azure Blob elseif ($ExternalMods -like "AzureBlob") { - Write-Log "Azure Blob Storage set as mod source" - Write-Log "Checking AZCopy" + Write-ToLog "Azure Blob Storage set as mod source" + Write-ToLog "Checking AZCopy" Get-AZCopy $WingetUpdatePath #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)) { - 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 $AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine) @@ -163,12 +163,12 @@ function Test-ModsPath ($ModsPath, $WingetUpdatePath, $AzureBlobSASURL) { } if ($AZCopySyncErrorRegex.Match($_).Value) { - Write-Log "AZCopy Sync Error! $_" + Write-ToLog "AZCopy Sync Error! $_" } } } else { - Write-Log "Error 'azcopy.exe' or SAS Token not found!" + Write-ToLog "Error 'azcopy.exe' or SAS Token not found!" } return $ModsUpdated, $DeletedMods diff --git a/Winget-AutoUpdate/functions/Test-Network.ps1 b/Winget-AutoUpdate/functions/Test-Network.ps1 index 7478ae7..5e4fc4f 100644 --- a/Winget-AutoUpdate/functions/Test-Network.ps1 +++ b/Winget-AutoUpdate/functions/Test-Network.ps1 @@ -9,7 +9,7 @@ function Test-Network { $ProgressPreference = 'SilentlyContinue' #Test connectivity during 30 min then timeout - Write-Log "Checking internet connection..." "Yellow" + Write-ToLog "Checking internet connection..." "Yellow" While ($timeout -lt 1800) { $URLtoTest = "https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE" @@ -17,7 +17,7 @@ function Test-Network { if ($URLcontent -like "*MIT License*") { - Write-Log "Connected !" "Green" + Write-ToLog "Connected !" "Green" #Check for metered connection [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")) { - Write-Log "Metered connection detected." "Yellow" + Write-ToLog "Metered connection detected." "Yellow" 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 } 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 } @@ -56,7 +56,7 @@ function Test-Network { #Send Warning Notif if no connection for 5 min if ($timeout -eq 300) { #Log - Write-Log "Notify 'No connection' sent." "Yellow" + Write-ToLog "Notify 'No connection' sent." "Yellow" #Notif $Title = $NotifLocale.local.outputs.output[0].title @@ -71,7 +71,7 @@ function Test-Network { } #Send Timeout Notif if no connection for 30 min - Write-Log "Timeout. No internet connection !" "Red" + Write-ToLog "Timeout. No internet connection !" "Red" #Notif $Title = $NotifLocale.local.outputs.output[1].title diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 5928308..95b3064 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -9,7 +9,7 @@ Function Update-App ($app) { } #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) $Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion) $MessageType = "info" @@ -20,26 +20,26 @@ Function Update-App ($app) { $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) #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 ($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" } #Run Winget Upgrade command 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 } 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 } 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" } @@ -53,25 +53,25 @@ Function Update-App ($app) { #Test for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities) $PendingReboot = Test-PendingReboot 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 break } #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) { - 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 } 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 } 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" } @@ -87,18 +87,18 @@ Function Update-App ($app) { if ($FailedToUpgrade -eq $false) { 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" } } - 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 if ($FailedToUpgrade -eq $false) { #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 $Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name) @@ -113,7 +113,7 @@ Function Update-App ($app) { else { #Send failed updated app notification - Write-Log "$($app.Name) update failed." "Red" + Write-ToLog "$($app.Name) update failed." "Red" #Send Notif $Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name) diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1 index 6fe3aa2..0b2f22f 100644 --- a/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -19,24 +19,24 @@ function Update-WAU { New-Item $ZipFile -ItemType File -Force | Out-Null #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 #Extract Zip File - Write-Log "Unzipping the WAU GitHub Repository" "Cyan" + Write-ToLog "Unzipping the WAU GitHub Repository" "Cyan" $location = "$WorkingDir\WAU_update" Expand-Archive -Path $ZipFile -DestinationPath $location -Force Get-ChildItem -Path $location -Recurse | Unblock-File #Update scritps - Write-Log "Updating WAU" "Yellow" + Write-ToLog "Updating WAU" "Yellow" $TempPath = (Resolve-Path "$location\*\Winget-AutoUpdate\")[0].Path if ($TempPath) { Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force } #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 $location -Recurse -Force -ErrorAction SilentlyContinue @@ -49,14 +49,14 @@ function Update-WAU { $WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 1 -Force #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" $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion $MessageType = "success" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text #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`"" exit @@ -70,7 +70,7 @@ function Update-WAU { $Message = $NotifLocale.local.outputs.output[4].message $MessageType = "error" Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text - Write-Log "WAU Update failed" "Red" + Write-ToLog "WAU Update failed" "Red" } diff --git a/Winget-AutoUpdate/functions/Write-Log.ps1 b/Winget-AutoUpdate/functions/Write-ToLog.ps1 similarity index 80% rename from Winget-AutoUpdate/functions/Write-Log.ps1 rename to Winget-AutoUpdate/functions/Write-ToLog.ps1 index e30f6f1..db1116e 100644 --- a/Winget-AutoUpdate/functions/Write-Log.ps1 +++ b/Winget-AutoUpdate/functions/Write-ToLog.ps1 @@ -1,6 +1,6 @@ #Write to Log Function -function Write-Log ($LogMsg, $LogColor = "White") { +function Write-ToLog ($LogMsg, $LogColor = "White") { #Get log $Log = "$(Get-Date -UFormat "%T") - $LogMsg"