Minor format changes

pull/398/head
Joerg Hochwald 2023-09-15 16:38:54 +02:00
parent 1320e7d356
commit 6c118323f9
No known key found for this signature in database
31 changed files with 1364 additions and 1214 deletions

View File

@ -91,28 +91,57 @@
#>
[CmdletBinding()]
param(
[Alias('S')] [Switch] $Silent = $false,
[Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
[Alias('List')] [String] $ListPath,
[Alias('Mods')] [String] $ModsPath,
[Alias('AzureBlobURL')] [String] $AzureBlobSASURL,
[Switch] $DoNotUpdate = $false,
[Switch] $DisableWAUAutoUpdate = $false,
[Switch] $RunOnMetered = $false,
[Switch] $Uninstall = $false,
[Switch] $NoClean = $false,
[Switch] $DesktopShortcut = $false,
[Switch] $StartMenuShortcut = $false,
[Switch] $UseWhiteList = $false,
[ValidateSet('Full', 'SuccessOnly', 'None')] [String] $NotificationLevel = 'Full',
[Switch] $UpdatesAtLogon = $false,
[ValidateSet('Daily', 'BiDaily', 'Weekly', 'BiWeekly', 'Monthly', 'Never')] [String] $UpdatesInterval = 'Daily',
[DateTime] $UpdatesAtTime = ('06am'),
[Switch] $BypassListForUsers = $false,
[Switch] $InstallUserContext = $false,
[ValidateRange(0, 99)] [int] $MaxLogFiles = 3,
[long] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
param (
[Alias('S')]
[Switch]
$Silent = $false,
[Alias('Path')]
[String]
$WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
[Alias('List')]
[String]
$ListPath,
[Alias('Mods')]
[String]
$ModsPath,
[Alias('AzureBlobURL')]
[String]
$AzureBlobSASURL,
[Switch]
$DoNotUpdate = $false,
[Switch]
$DisableWAUAutoUpdate = $false,
[Switch]
$RunOnMetered = $false,
[Switch]
$Uninstall = $false,
[Switch]
$NoClean = $false,
[Switch]
$DesktopShortcut = $false,
[Switch]
$StartMenuShortcut = $false,
[Switch]
$UseWhiteList = $false,
[ValidateSet('Full', 'SuccessOnly', 'None')]
[String]
$NotificationLevel = 'Full',
[Switch]
$UpdatesAtLogon = $false,
[ValidateSet('Daily', 'BiDaily', 'Weekly', 'BiWeekly', 'Monthly', 'Never')]
[String]
$UpdatesInterval = 'Daily',
[DateTime]
$UpdatesAtTime = ('06am'),
[Switch]
$BypassListForUsers = $false,
[Switch]
$InstallUserContext = $false,
[ValidateRange(0, 99)]
[int]
$MaxLogFiles = 3,
[long]
$MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
)
@ -203,11 +232,11 @@ function Install-WinGet
}
#Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
If ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
if ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
{
Write-Host -Object 'Winget is Installed' -ForegroundColor Green
}
Else
else
{
Write-Host -Object '-> Winget is not installed:'
@ -646,13 +675,9 @@ function Add-Shortcut
param
(
$Target,
$Shortcut,
$Arguments,
$Icon,
$Description
)
$WScriptShell = New-Object -ComObject WScript.Shell
@ -678,7 +703,7 @@ if ("$env:PROCESSOR_ARCHITEW6432" -ne 'ARM64')
if (Test-Path -Path "$($env:windir)\SysNative\WindowsPowerShell\v1.0\powershell.exe")
{
Start-Process -FilePath "$($env:windir)\SysNative\WindowsPowerShell\v1.0\powershell.exe" -Wait -NoNewWindow -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command $($MyInvocation.line)"
Exit $lastexitcode
exit $lastexitcode
}
}

View File

@ -18,16 +18,18 @@
#>
[CmdletBinding()]
param(
[Switch] $Logs = $False,
[Switch] $Help = $False
param (
[Switch]
$Logs = $False,
[Switch]
$Help = $False
)
function Test-WAUisRunning
{
If (((Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue).State -eq 'Running') -or ((Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue).State -eq 'Running'))
if (((Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue).State -eq 'Running') -or ((Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue).State -eq 'Running'))
{
Return $True
return $True
}
}
@ -84,7 +86,7 @@ else
$MessageType = 'info'
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun
# Sleep until the task is done
While (Test-WAUisRunning)
while (Test-WAUisRunning)
{
Start-Sleep -Seconds 3
}

View File

@ -14,8 +14,9 @@
#>
[CmdletBinding()]
param(
[Switch] $NoClean = $false
param (
[Switch]
$NoClean = $false
)
Write-Host -Object "`n"

View File

@ -4,7 +4,9 @@
$Script:WorkingDir = $PSScriptRoot
# Get Functions
Get-ChildItem -Path "$WorkingDir\functions" | ForEach-Object { . $_.FullName }
Get-ChildItem -Path "$WorkingDir\functions" | ForEach-Object {
. $_.FullName
}
<# MAIN #>
@ -18,55 +20,66 @@ Start-Init
$Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate')
#Log running context and more...
if ($IsSystem) {
Write-ToLog 'Running in System context'
if ($IsSystem)
{
Write-ToLog 'Running in System context'
#Get and set Domain/Local Policies (GPO)
$ActivateGPOManagement, $ChangedSettings = Get-Policies
if ($ActivateGPOManagement) {
Write-ToLog 'Activated WAU GPO Management detected, comparing...'
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) {
Write-ToLog 'Changed settings detected and applied' 'Yellow'
}
else {
Write-ToLog 'No Changed settings detected' 'Yellow'
}
}
#Get and set Domain/Local Policies (GPO)
$ActivateGPOManagement, $ChangedSettings = Get-Policies
if ($ActivateGPOManagement)
{
Write-ToLog 'Activated WAU GPO Management detected, comparing...'
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0)
{
Write-ToLog 'Changed settings detected and applied' 'Yellow'
}
else
{
Write-ToLog 'No Changed settings detected' 'Yellow'
}
}
# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
if ($null -eq $MaxLogFiles) {
[int] $MaxLogFiles = 3
}
else {
[int] $MaxLogFiles = $MaxLogFiles
}
# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
if ($null -eq $MaxLogFiles)
{
[int]$MaxLogFiles = 3
}
else
{
[int]$MaxLogFiles = $MaxLogFiles
}
# Maximum size of log file.
$MaxLogSize = $WAUConfig.WAU_MaxLogSize
if (!$MaxLogSize) {
[long] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
}
else {
[long] $MaxLogSize = $MaxLogSize
}
# Maximum size of log file.
$MaxLogSize = $WAUConfig.WAU_MaxLogSize
if (!$MaxLogSize)
{
[long]$MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
}
else
{
[long]$MaxLogSize = $MaxLogSize
}
#LogRotation if System
$LogRotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize
if ($LogRotate -eq $False) {
Write-ToLog 'An Exception occured during Log Rotation...'
}
#LogRotation if System
$LogRotate = Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize
if ($LogRotate -eq $False)
{
Write-ToLog 'An Exception occured during Log Rotation...'
}
#Run post update actions if necessary if run as System
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) {
Invoke-PostUpdateActions
}
#Run Scope Machine funtion if run as System
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
Add-ScopeMachine $SettingsPath
#Run post update actions if necessary if run as System
if (!($WAUConfig.WAU_PostUpdateActions -eq 0))
{
Invoke-PostUpdateActions
}
#Run Scope Machine funtion if run as System
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
Add-ScopeMachine $SettingsPath
}
else {
Write-ToLog 'Running in User context'
else
{
Write-ToLog 'Running in User context'
}
#Get Notif Locale function
@ -74,270 +87,331 @@ $LocaleDisplayName = Get-NotifLocale
Write-ToLog "Notification Level: $($WAUConfig.WAU_NotificationLevel). Notification Language: $LocaleDisplayName" 'Cyan'
#Check network connectivity
if (Test-Network) {
#Check if Winget is installed and get Winget cmd
$TestWinget = Get-WingetCmd
if (Test-Network)
{
#Check if Winget is installed and get Winget cmd
$TestWinget = Get-WingetCmd
if ($TestWinget) {
#Get Current Version
$WAUCurrentVersion = $WAUConfig.DisplayVersion
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-ToLog 'WAU AutoUpdate is Disabled.' 'Gray'
if ($TestWinget)
{
#Get Current Version
$WAUCurrentVersion = $WAUConfig.DisplayVersion
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-ToLog 'WAU AutoUpdate is Disabled.' 'Gray'
}
else
{
Write-ToLog 'WAU AutoUpdate is Enabled.' 'Green'
#Get Available Version
$Script:WAUAvailableVersion = Get-WAUAvailableVersion
#Compare
if ([version]$WAUAvailableVersion.Replace('-', '.') -ne [version]$WAUCurrentVersion.Replace('-', '.'))
{
#If new version is available, update it
Write-ToLog "WAU Available version: $WAUAvailableVersion" 'Yellow'
Update-WAU
}
else {
Write-ToLog 'WAU AutoUpdate is Enabled.' 'Green'
#Get Available Version
$Script:WAUAvailableVersion = Get-WAUAvailableVersion
#Compare
if ([version]$WAUAvailableVersion.Replace('-', '.') -ne [version]$WAUCurrentVersion.Replace('-', '.')) {
#If new version is available, update it
Write-ToLog "WAU Available version: $WAUAvailableVersion" 'Yellow'
Update-WAU
}
else {
Write-ToLog 'WAU is up to date.' 'Green'
}
else
{
Write-ToLog 'WAU is up to date.' 'Green'
}
}
#Delete previous list_/winget_error (if they exist) if run as System
if (Test-Path -Path "$WorkingDir\logs\error.txt") {
Remove-Item -Path "$WorkingDir\logs\error.txt" -Force
#Delete previous list_/winget_error (if they exist) if run as System
if (Test-Path -Path "$WorkingDir\logs\error.txt")
{
Remove-Item -Path "$WorkingDir\logs\error.txt" -Force
}
#Get External ListPath if run as System
if ($WAUConfig.WAU_ListPath)
{
$ListPathClean = $($WAUConfig.WAU_ListPath.TrimEnd(' ', '\', '/'))
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-ToLog "Couldn't reach/find/compare/copy from $ListPathClean..." 'Red'
if ($ListPathClean -notlike 'http*')
{
if (Test-Path -Path "$ListPathClean" -PathType Leaf)
{
Write-ToLog 'PATH must end with a Directory, not a File...' 'Red'
}
}
else
{
if ($ListPathClean -match '_apps.txt')
{
Write-ToLog 'PATH must end with a Directory, not a File...' 'Red'
}
}
$Script:ReachNoPath = $False
}
if ($NewList)
{
Write-ToLog "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))" 'Yellow'
}
else
{
if ($WAUConfig.WAU_UseWhiteList -and (Test-Path -Path "$WorkingDir\included_apps.txt"))
{
Write-ToLog 'List (white) is up to date.' 'Green'
}
elseif (!$WAUConfig.WAU_UseWhiteList -and (Test-Path -Path "$WorkingDir\excluded_apps.txt"))
{
Write-ToLog 'List (black) is up to date.' 'Green'
}
else
{
Write-ToLog "Critical: White/Black List doesn't exist, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "White/Black List doesn't exist" -Force
exit 1
}
}
}
}
#Get External ListPath if run as System
if ($WAUConfig.WAU_ListPath) {
$ListPathClean = $($WAUConfig.WAU_ListPath.TrimEnd(' ', '\', '/'))
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-ToLog "Couldn't reach/find/compare/copy from $ListPathClean..." 'Red'
if ($ListPathClean -notlike 'http*') {
if (Test-Path -Path "$ListPathClean" -PathType Leaf) {
Write-ToLog 'PATH must end with a Directory, not a File...' 'Red'
}
}
else {
if ($ListPathClean -match '_apps.txt') {
Write-ToLog 'PATH must end with a Directory, not a File...' 'Red'
}
}
$Script:ReachNoPath = $False
}
if ($NewList) {
Write-ToLog "Newer List downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))" 'Yellow'
}
else {
if ($WAUConfig.WAU_UseWhiteList -and (Test-Path -Path "$WorkingDir\included_apps.txt")) {
Write-ToLog 'List (white) is up to date.' 'Green'
}
elseif (!$WAUConfig.WAU_UseWhiteList -and (Test-Path -Path "$WorkingDir\excluded_apps.txt")) {
Write-ToLog 'List (black) is up to date.' 'Green'
}
else {
Write-ToLog "Critical: White/Black List doesn't exist, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "White/Black List doesn't exist" -Force
Exit 1
}
}
}
#Get External ModsPath if run as System
if ($WAUConfig.WAU_ModsPath)
{
$ModsPathClean = $($WAUConfig.WAU_ModsPath.TrimEnd(' ', '\', '/'))
Write-ToLog "WAU uses External Mods from: $ModsPathClean"
if ($WAUConfig.WAU_AzureBlobSASURL)
{
$NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\') $WAUConfig.WAU_AzureBlobSASURL.TrimEnd(' ')
}
#Get External ModsPath if run as System
if ($WAUConfig.WAU_ModsPath) {
$ModsPathClean = $($WAUConfig.WAU_ModsPath.TrimEnd(' ', '\', '/'))
Write-ToLog "WAU uses External Mods from: $ModsPathClean"
if ($WAUConfig.WAU_AzureBlobSASURL) {
$NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\') $WAUConfig.WAU_AzureBlobSASURL.TrimEnd(' ')
}
else {
$NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\')
}
if ($ReachNoPath) {
Write-ToLog "Couldn't reach/find/compare/copy from $ModsPathClean..." 'Red'
$Script:ReachNoPath = $False
}
if ($NewMods -gt 0) {
Write-ToLog "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Yellow'
}
else {
if (Test-Path -Path "$WorkingDir\mods\*.ps1") {
Write-ToLog 'Mods are up to date.' 'Green'
}
else {
Write-ToLog 'No Mods are implemented...' 'Yellow'
}
}
if ($DeletedMods -gt 0) {
Write-ToLog "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Red'
}
else
{
$NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\')
}
#Test if _WAU-mods.ps1 exist: Mods for WAU (if Network is active/any Winget is installed/running as SYSTEM)
$Mods = "$WorkingDir\mods"
if (Test-Path -Path "$Mods\_WAU-mods.ps1") {
Write-ToLog 'Running Mods for WAU...' 'Yellow'
& "$Mods\_WAU-mods.ps1"
$ModsExitCode = $LASTEXITCODE
#If _WAU-mods.ps1 has ExitCode 1 - Re-run WAU
if ($ModsExitCode -eq 1) {
Write-ToLog 'Re-run WAU'
Start-Process -FilePath powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`""
Exit
}
if ($ReachNoPath)
{
Write-ToLog "Couldn't reach/find/compare/copy from $ModsPathClean..." 'Red'
$Script:ReachNoPath = $False
}
}
if ($($WAUConfig.WAU_ListPath) -eq 'GPO') {
$Script:GPOList = $True
}
#Get White or Black list
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
Write-ToLog 'WAU uses White List config'
$toUpdate = Get-IncludedApps
$UseWhiteList = $true
}
else {
Write-ToLog 'WAU uses Black List config'
$toSkip = Get-ExcludedApps
}
#Fix and count the array if GPO List as ERROR handling!
if ($GPOList) {
if ($UseWhiteList) {
$WhiteList = $toUpdate.GetUpperBound(0)
if ($null -eq $WhiteList) {
Write-ToLog "Critical: Whitelist doesn't exist in GPO, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "Whitelist doesn't exist in GPO" -Force
Exit 1
}
$toUpdate = $toUpdate.Data
if ($NewMods -gt 0)
{
Write-ToLog "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Yellow'
}
else {
$BlackList = $toSkip.GetUpperBound(0)
if ($null -eq $BlackList) {
Write-ToLog "Critical: Blacklist doesn't exist in GPO, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force
Exit 1
}
$toSkip = $toSkip.Data
else
{
if (Test-Path -Path "$WorkingDir\mods\*.ps1")
{
Write-ToLog 'Mods are up to date.' 'Green'
}
else
{
Write-ToLog 'No Mods are implemented...' 'Yellow'
}
}
}
#Get outdated Winget packages
Write-ToLog 'Checking application updates on Winget Repository...' 'yellow'
$outdated = Get-WingetOutdatedApps
#If something unusual happened
if ($outdated -like 'An unusual*') {
Write-ToLog "$outdated" 'cyan'
$outdated = $False
}
#Run only if $outdated is populated!
if ($outdated) {
#Log list of app to update
foreach ($app in $outdated) {
#List available updates
$Log = "-> Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
$Log | Write-host
$Log | out-file -filepath $LogFile -Append
if ($DeletedMods -gt 0)
{
Write-ToLog "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Red'
}
}
#Count good update installations
$Script:InstallOK = 0
#Trick under user context when -BypassListForUsers is used
if ($IsSystem -eq $false -and $WAUConfig.WAU_BypassListForUsers -eq 1) {
Write-ToLog 'Bypass system list in user context is Enabled.'
$UseWhiteList = $false
$toSkip = $null
#Test if _WAU-mods.ps1 exist: Mods for WAU (if Network is active/any Winget is installed/running as SYSTEM)
$Mods = "$WorkingDir\mods"
if (Test-Path -Path "$Mods\_WAU-mods.ps1")
{
Write-ToLog 'Running Mods for WAU...' 'Yellow'
& "$Mods\_WAU-mods.ps1"
$ModsExitCode = $LASTEXITCODE
#If _WAU-mods.ps1 has ExitCode 1 - Re-run WAU
if ($ModsExitCode -eq 1)
{
Write-ToLog 'Re-run WAU'
Start-Process -FilePath powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`""
exit
}
}
#If White List
if ($UseWhiteList) {
#For each app, notify and update
foreach ($app in $outdated) {
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne 'Unknown') {
Update-App $app
}
#if current app version is unknown
elseif ($($app.Version) -eq 'Unknown') {
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray'
}
#if app is in "excluded list"
else {
Write-ToLog "$($app.Name) : Skipped upgrade because it is not in the included app list" 'Gray'
}
}
}
if ($($WAUConfig.WAU_ListPath) -eq 'GPO')
{
$Script:GPOList = $True
}
#Get White or Black list
if ($WAUConfig.WAU_UseWhiteList -eq 1)
{
Write-ToLog 'WAU uses White List config'
$toUpdate = Get-IncludedApps
$UseWhiteList = $true
}
else
{
Write-ToLog 'WAU uses Black List config'
$toSkip = Get-ExcludedApps
}
#Fix and count the array if GPO List as ERROR handling!
if ($GPOList)
{
if ($UseWhiteList)
{
$WhiteList = $toUpdate.GetUpperBound(0)
if ($null -eq $WhiteList)
{
Write-ToLog "Critical: Whitelist doesn't exist in GPO, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "Whitelist doesn't exist in GPO" -Force
exit 1
}
#If Black List or default
else {
#For each app, notify and update
foreach ($app in $outdated) {
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne 'Unknown') {
Update-App $app
}
#if current app version is unknown
elseif ($($app.Version) -eq 'Unknown') {
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray'
}
#if app is in "excluded list"
else {
Write-ToLog "$($app.Name) : Skipped upgrade because it is in the excluded app list" 'Gray'
}
}
$toUpdate = $toUpdate.Data
}
else
{
$BlackList = $toSkip.GetUpperBound(0)
if ($null -eq $BlackList)
{
Write-ToLog "Critical: Blacklist doesn't exist in GPO, exiting..." 'Red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force
exit 1
}
$toSkip = $toSkip.Data
}
}
if ($InstallOK -gt 0) {
Write-ToLog "$InstallOK apps updated ! No more update." 'Green'
#Get outdated Winget packages
Write-ToLog 'Checking application updates on Winget Repository...' 'yellow'
$outdated = Get-WingetOutdatedApps
#If something unusual happened
if ($outdated -like 'An unusual*')
{
Write-ToLog "$outdated" 'cyan'
$outdated = $False
}
#Run only if $outdated is populated!
if ($outdated)
{
#Log list of app to update
foreach ($app in $outdated)
{
#List available updates
$Log = "-> Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
$Log | Write-host
$Log | out-file -filepath $LogFile -Append
}
#Count good update installations
$Script:InstallOK = 0
#Trick under user context when -BypassListForUsers is used
if ($IsSystem -eq $false -and $WAUConfig.WAU_BypassListForUsers -eq 1)
{
Write-ToLog 'Bypass system list in user context is Enabled.'
$UseWhiteList = $false
$toSkip = $null
}
#If White List
if ($UseWhiteList)
{
#For each app, notify and update
foreach ($app in $outdated)
{
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne 'Unknown')
{
Update-App $app
}
#if current app version is unknown
elseif ($($app.Version) -eq 'Unknown')
{
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray'
}
#if app is in "excluded list"
else
{
Write-ToLog "$($app.Name) : Skipped upgrade because it is not in the included app list" 'Gray'
}
}
}
if ($InstallOK -eq 0 -or !$InstallOK) {
Write-ToLog 'No new update.' 'Green'
}
#Check if any user is logged on if System and run User task (if installed)
if ($IsSystem) {
#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-ToLog 'No explorer process found / Nobody interactively logged on...'
}
#If Black List or default
else
{
#For each app, notify and update
foreach ($app in $outdated)
{
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne 'Unknown')
{
Update-App $app
}
#if current app version is unknown
elseif ($($app.Version) -eq 'Unknown')
{
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray'
}
#if app is in "excluded list"
else
{
Write-ToLog "$($app.Name) : Skipped upgrade because it is in the excluded app list" 'Gray'
}
}
Else {
#Run WAU in user context if the user task exist
$UserScheduledTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
if ($UserScheduledTask) {
}
#Get Winget system apps to excape them befor running user context
Write-ToLog 'User logged on, get a list of installed Winget apps in System context...'
Get-WingetSystemApps
if ($InstallOK -gt 0)
{
Write-ToLog "$InstallOK apps updated ! No more update." 'Green'
}
}
#Run user context scheduled task
Write-ToLog 'Starting WAU in User context'
Start-ScheduledTask -TaskName $UserScheduledTask.TaskName -ErrorAction SilentlyContinue
Exit 0
}
elseif (!$UserScheduledTask) {
Write-ToLog 'User context execution not installed...'
}
if ($InstallOK -eq 0 -or !$InstallOK)
{
Write-ToLog 'No new update.' 'Green'
}
#Check if any user is logged on if System and run User task (if installed)
if ($IsSystem)
{
#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-ToLog 'No explorer process found / Nobody interactively logged on...'
}
else
{
#Run WAU in user context if the user task exist
$UserScheduledTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
if ($UserScheduledTask)
{
#Get Winget system apps to excape them befor running user context
Write-ToLog 'User logged on, get a list of installed Winget apps in System context...'
Get-WingetSystemApps
#Run user context scheduled task
Write-ToLog 'Starting WAU in User context'
Start-ScheduledTask -TaskName $UserScheduledTask.TaskName -ErrorAction SilentlyContinue
exit 0
}
}
}
else {
Write-ToLog 'Critical: Winget not installed or detected, exiting...' 'red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value 'Winget not installed or detected' -Force
Write-ToLog 'End of process!' 'Cyan'
Exit 1
}
elseif (!$UserScheduledTask)
{
Write-ToLog 'User context execution not installed...'
}
}
}
}
else
{
Write-ToLog 'Critical: Winget not installed or detected, exiting...' 'red'
New-Item -Path "$WorkingDir\logs\error.txt" -Value 'Winget not installed or detected' -Force
Write-ToLog 'End of process!' 'Cyan'
exit 1
}
}
#End

View File

@ -4,19 +4,21 @@ function Add-ScopeMachine
[CmdletBinding()]
param
(
[string]$SettingsPath
[string]
$SettingsPath
)
if (Test-Path -Path $SettingsPath -ErrorAction SilentlyContinue)
{
$ConfigFile = (Get-Content -Path $SettingsPath -ErrorAction SilentlyContinue | Where-Object -FilterScript {
($_ -notmatch '//')
} | ConvertFrom-Json)
} | ConvertFrom-Json)
}
if (!$ConfigFile)
{
$ConfigFile = @{}
$ConfigFile = @{
}
}
if ($ConfigFile.installBehavior.preferences.scope)
@ -27,10 +29,10 @@ function Add-ScopeMachine
{
$Scope = (New-Object -TypeName PSObject -Property $(@{
scope = 'Machine'
}))
}))
$Preference = (New-Object -TypeName PSObject -Property $(@{
preferences = $Scope
}))
}))
$null = (Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force)
}

View File

@ -4,11 +4,16 @@ function Add-Shortcut
[CmdletBinding()]
param
(
[string]$Target,
[string]$Shortcut,
[string]$Arguments,
[string]$Icon,
[string]$Description
[string]
$Target,
[string]
$Shortcut,
[string]
$Arguments,
[string]
$Icon,
[string]
$Description
)
$WScriptShell = (New-Object -ComObject WScript.Shell)

View File

@ -1,12 +1,14 @@
Function Confirm-Installation
function Confirm-Installation
{
# Set json export file
[CmdletBinding()]
param
(
[string]$AppName,
[string]$AppVer
[string]
$AppName,
[string]
$AppVer
)
$JsonFile = ('{0}\Config\InstalledApps.json' -f $WorkingDir)

View File

@ -1,11 +1,12 @@
# Function to get AZCopy, if it doesn't exist and update it, if it does
Function Get-AZCopy
function Get-AZCopy
{
[CmdletBinding()]
param
(
[string]$WingetUpdatePath
[string]
$WingetUpdatePath
)
$AZCopyLink = (Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue).headers.location
@ -21,19 +22,19 @@ Function Get-AZCopy
{
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-ToLog -LogMsg ('AZCopy version {0} found' -f $AZCopyCurrentVersion)
Write-ToLog -LogMsg ('AZCopy version {0} found' -f $AZCopyCurrentVersion)
}
else
{
Write-ToLog -LogMsg 'AZCopy not already installed'
Write-ToLog -LogMsg 'AZCopy not already installed'
$AZCopyCurrentVersion = '0.0.0'
}
if (([version] $AZCopyCurrentVersion) -lt ([version] $AZCopyLatestVersion))
if (([version]$AZCopyCurrentVersion) -lt ([version]$AZCopyLatestVersion))
{
Write-ToLog -LogMsg ('Installing version {0} of AZCopy' -f $AZCopyLatestVersion)
Write-ToLog -LogMsg ('Installing version {0} of AZCopy' -f $AZCopyLatestVersion)
$null = (Invoke-WebRequest -Uri $AZCopyLink -UseBasicParsing -OutFile ('{0}\azcopyv10.zip' -f $WingetUpdatePath))
Write-ToLog -LogMsg 'Extracting AZCopy zip file'
Write-ToLog -LogMsg 'Extracting AZCopy zip file'
$null = (Expand-Archive -Path ('{0}\azcopyv10.zip' -f $WingetUpdatePath) -DestinationPath $WingetUpdatePath -Force -Confirm:$false)
$AZCopyPathSearch = (Resolve-Path -Path ('{0}\azcopy_*' -f $WingetUpdatePath))
@ -46,13 +47,13 @@ Function Get-AZCopy
$AZCopyEXEPath = $AZCopyPathSearch
}
Write-ToLog -LogMsg "Copying 'azcopy.exe' to main folder"
Write-ToLog -LogMsg "Copying 'azcopy.exe' to main folder"
$null = (Copy-Item -Path ('{0}\azcopy.exe' -f $AZCopyEXEPath) -Destination ('{0}\' -f $WingetUpdatePath) -Force -Confirm:$false)
Write-ToLog -LogMsg 'Removing temporary AZCopy files'
Write-ToLog -LogMsg 'Removing temporary AZCopy files'
$null = (Remove-Item -Path $AZCopyEXEPath -Recurse -Force -Confirm:$false)
$null = (Remove-Item -Path ('{0}\azcopyv10.zip' -f $WingetUpdatePath) -Force -Confirm:$false)
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-ToLog -LogMsg ('AZCopy version {0} installed' -f $AZCopyCurrentVersion)
Write-ToLog -LogMsg ('AZCopy version {0} installed' -f $AZCopyCurrentVersion)
}
}

View File

@ -1,12 +1,13 @@
# Get the winget App Information
Function Get-AppInfo
function Get-AppInfo
{
# Get AppID Info
[CmdletBinding()]
param
(
[string]$AppID
[string]
$AppID
)
$String = (& $winget show $AppID --accept-source-agreements -s winget | Out-String)

View File

@ -1,28 +1,31 @@
#Function to get the locale file for notifications
Function Get-NotifLocale {
function Get-NotifLocale
{
# Get OS locale
$OSLocale = (Get-UICulture).Parent
# Get OS locale
$OSLocale = (Get-UICulture).Parent
# Test if OS locale notif file exists
$TestOSLocalPath = ('{0}\locale\{1}.xml' -f $WorkingDir, $OSLocale.Name)
# Test if OS locale notif file exists
$TestOSLocalPath = ('{0}\locale\{1}.xml' -f $WorkingDir, $OSLocale.Name)
# Set OS Local if file exists
if (Test-Path -Path $TestOSLocalPath -ErrorAction SilentlyContinue) {
$LocaleDisplayName = $OSLocale.DisplayName
$LocaleFile = $TestOSLocalPath
}
else {
# Set English if file doesn't exist
$LocaleDisplayName = 'English'
$LocaleFile = ('{0}\locale\en.xml' -f $WorkingDir)
}
# Set OS Local if file exists
if (Test-Path -Path $TestOSLocalPath -ErrorAction SilentlyContinue)
{
$LocaleDisplayName = $OSLocale.DisplayName
$LocaleFile = $TestOSLocalPath
}
else
{
# Set English if file doesn't exist
$LocaleDisplayName = 'English'
$LocaleFile = ('{0}\locale\en.xml' -f $WorkingDir)
}
# Get locale XML file content
[xml]$Script:NotifLocale = (Get-Content -Path $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue)
# Get locale XML file content
[xml]$Script:NotifLocale = (Get-Content -Path $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue)
# Rerturn langague display name
Return $LocaleDisplayName
# Rerturn langague display name
return $LocaleDisplayName
}

View File

@ -1,6 +1,6 @@
# Function to get the Domain/Local Policies (GPO)
Function Get-Policies
function Get-Policies
{
# Get WAU Policies and set the Configurations Registry Accordingly
$WAUPolicies = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate' -ErrorAction SilentlyContinue)
@ -196,7 +196,8 @@ Function Get-Policies
$task = $folder.GetTask('Winget-AutoUpdate')
$definition = $task.Definition
$null = $definition.Triggers.Count
switch ($($WAUPolicies.WAU_UpdatesInterval)) {
switch ($($WAUPolicies.WAU_UpdatesInterval))
{
'Daily'
{
$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime)
@ -466,5 +467,5 @@ Function Get-Policies
}
}
Return $($WAUPolicies.WAU_ActivateGPOManagement), $ChangedSettings
return $($WAUPolicies.WAU_ActivateGPOManagement), $ChangedSettings
}

View File

@ -1,43 +1,53 @@
# Function to get the winget command regarding execution context (User, System...)
Function Get-WingetCmd {
function Get-WingetCmd
{
# Get WinGet Path (if Admin context)
# Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard)
$ResolveWingetPath = (Resolve-Path -Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object -Property { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') })
# Get WinGet Path (if Admin context)
# Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard)
$ResolveWingetPath = (Resolve-Path -Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object -Property {
[version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1')
})
if ($ResolveWingetPath) {
# If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
}
if ($ResolveWingetPath)
{
# If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
}
#If running under System or Admin context obtain Winget from Program Files
if((([Security.Principal.WindowsIdentity]::GetCurrent().User) -eq 'S-1-5-18') -or ($WingetPath)){
if (Test-Path -Path ('{0}\winget.exe' -f $WingetPath) -ErrorAction SilentlyContinue) {
$Script:Winget = ('{0}\winget.exe' -f $WingetPath)
}
}else{
#Get Winget Location in User context
$WingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue)
#If running under System or Admin context obtain Winget from Program Files
if ((([Security.Principal.WindowsIdentity]::GetCurrent().User) -eq 'S-1-5-18') -or ($WingetPath))
{
if (Test-Path -Path ('{0}\winget.exe' -f $WingetPath) -ErrorAction SilentlyContinue)
{
$Script:Winget = ('{0}\winget.exe' -f $WingetPath)
}
}
else
{
#Get Winget Location in User context
$WingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue)
if ($WingetCmd) {
$Script:Winget = $WingetCmd.Source
}
}
if ($WingetCmd)
{
$Script:Winget = $WingetCmd.Source
}
}
If(!($Script:Winget)){
Write-ToLog 'Winget not installed or detected !' 'Red'
if (!($Script:Winget))
{
Write-ToLog 'Winget not installed or detected !' 'Red'
return $false
}
return $false
}
# Run winget to list apps and accept source agrements (necessary on first run)
$null = (& $Winget list --accept-source-agreements -s winget)
# Run winget to list apps and accept source agrements (necessary on first run)
$null = (& $Winget list --accept-source-agreements -s winget)
# Log Winget installed version
$WingetVer = & $Winget --version
Write-ToLog ('Winget Version: {0}' -f $WingetVer)
# Log Winget installed version
$WingetVer = & $Winget --version
Write-ToLog ('Winget Version: {0}' -f $WingetVer)
return $true
return $true
}

View File

@ -44,7 +44,7 @@ function Get-WingetOutdatedApps
# Now cycle in real package and split accordingly
$upgradeList = @()
For ($i = $fl + 2; $i -lt $lines.Length; $i++)
for ($i = $fl + 2; $i -lt $lines.Length; $i++)
{
$line = $lines[$i] -replace '[\u2026]', ' ' #Fix "..." in long names

View File

@ -15,9 +15,12 @@ function Invoke-LogRotation
#>
param
(
[string]$LogFile,
[int]$MaxLogFiles,
[int]$MaxLogSize
[string]
$LogFile,
[int]
$MaxLogFiles,
[int]
$MaxLogSize
)
try
@ -32,7 +35,7 @@ function Invoke-LogRotation
$logFileNameExtension = [IO.Path]::GetExtension($logFileName)
# if MaxLogFiles is 1 just keep the original one and let it grow
if (-not($MaxLogFiles -eq 1))
if (-not ($MaxLogFiles -eq 1))
{
if ($currentSize -ge $MaxLogSize)
{
@ -59,11 +62,11 @@ function Invoke-LogRotation
}
catch
{
Return $False
return $False
}
# if MaxLogFiles is 0 don't delete any old archived log files
if (-not($MaxLogFiles -eq 0))
if (-not ($MaxLogFiles -eq 0))
{
# set filter to search for archived log files
$archivedLogFileFilter = $logFileNameWithoutExtension + '??????????????' + $logFileNameExtension
@ -78,7 +81,7 @@ function Invoke-LogRotation
if (($oldLogFiles.Count + 1) -gt $MaxLogFiles)
{
[int]$numTooMany = (($oldLogFiles.Count) + 1) - $MaxLogFiles
$null = ($oldLogFiles | Sort-Object -Property 'LastWriteTime' | Select-Object -First $numTooMany | Remove-Item -Force -Confirm:$False -ErrorAction SilentlyContinue)
$null = ($oldLogFiles | Sort-Object -Property 'LastWriteTime' | Select-Object -First $numTooMany | Remove-Item -Force -Confirm:$False -ErrorAction SilentlyContinue)
}
}
}
@ -104,12 +107,12 @@ function Invoke-LogRotation
Write-ToLog -LogMsg ('Max Log Size reached: {0} bytes - Rotated Logs' -f $MaxLogSize)
Return $True
return $True
}
}
}
catch
{
Return $False
return $False
}
}

View File

@ -7,7 +7,8 @@ function Invoke-ModsProtect
[CmdletBinding()]
param
(
[string]$ModsPath
[string]
$ModsPath
)
try

View File

@ -26,7 +26,7 @@ function Invoke-PostUpdateActions
$Visual2022 = 'Microsoft Visual C++ 2015-2022 Redistributable*'
$path = (Get-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction SilentlyContinue | Where-Object -FilterScript {
$_.GetValue('DisplayName') -like $Visual2019 -or $_.GetValue('DisplayName') -like $Visual2022
})
})
# If not installed, install
if (!($path))
@ -69,11 +69,11 @@ function Invoke-PostUpdateActions
}
# Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
If ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
if ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
{
Write-ToLog -LogMsg '-> WinGet is Installed/up to date' -LogColor 'green'
}
Else
else
{
# Download WinGet MSIXBundle
Write-ToLog -LogMsg '-> Not installed/up to date. Downloading WinGet...'

View File

@ -3,17 +3,27 @@
function Start-NotifTask
{
[CmdletBinding()]
param(
[String]$Title = 'Winget-AutoUpdate',
[String]$Message,
[String]$MessageType,
[String]$Balise = 'WAU',
[String]$OnClickAction,
[String]$Body,
[String]$Button1Text,
[String]$Button1Action,
[Switch]$ButtonDismiss = $false,
[Switch]$UserRun = $false
param (
[String]
$Title = 'Winget-AutoUpdate',
[String]
$Message,
[String]
$MessageType,
[String]
$Balise = 'WAU',
[String]
$OnClickAction,
[String]
$Body,
[String]
$Button1Text,
[String]
$Button1Action,
[Switch]
$ButtonDismiss = $false,
[Switch]
$UserRun = $false
)
if (($WAUConfig.WAU_NotificationLevel -eq 'Full') -or ($WAUConfig.WAU_NotificationLevel -eq 'SuccessOnly' -and $MessageType -eq 'Success') -or ($UserRun))

View File

@ -6,9 +6,12 @@ function Test-ListPath
[CmdletBinding()]
param
(
[string]$ListPath,
[string]$UseWhiteList,
[string]$WingetUpdatePath
[string]
$ListPath,
[string]
$UseWhiteList,
[string]
$WingetUpdatePath
)
if ($UseWhiteList)

View File

@ -6,7 +6,8 @@ function Test-Mods
[CmdletBinding()]
param
(
[string]$app
[string]
$app
)
$ModsPreInstall = $null

View File

@ -8,9 +8,12 @@ function Test-ModsPath
[CmdletBinding()]
param
(
[string]$ModsPath,
[string]$WingetUpdatePath,
[string]$AzureBlobSASURL
[string]
$ModsPath,
[string]
$WingetUpdatePath,
[string]
$AzureBlobSASURL
)
$LocalMods = -join ($WingetUpdatePath, '\', 'mods')
$ExternalMods = $ModsPath
@ -64,7 +67,7 @@ function Test-ModsPath
foreach ($Bin in $InternalBinsNames)
{
If ($CleanLinks -notcontains $Bin)
if ($CleanLinks -notcontains $Bin)
{
$null = (Remove-Item -Path $LocalMods\bins\$Bin -Force -Confirm:$False -ErrorAction SilentlyContinue)
}
@ -122,7 +125,7 @@ function Test-ModsPath
foreach ($Mod in $InternalModsNames)
{
If ($CleanLinks -notcontains $Mod)
if ($CleanLinks -notcontains $Mod)
{
$null = (Remove-Item -Path $LocalMods\$Mod -Force -Confirm:$False -ErrorAction SilentlyContinue)
$DeletedMods++
@ -191,14 +194,14 @@ function Test-ModsPath
$AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync $AzureBlobSASURL $LocalMods --from-to BlobLocal --delete-destination=true
$AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine)
foreach ( $_ in $AZCopyOutputLines)
foreach ($_ in $AZCopyOutputLines)
{
$AZCopySyncAdditionsRegex = [regex]::new('(?<=Number of Copy Transfers Completed:\s+)\d+')
$AZCopySyncDeletionsRegex = [regex]::new('(?<=Number of Deletions at Destination:\s+)\d+')
$AZCopySyncErrorRegex = [regex]::new('^Cannot perform sync due to error:')
$AZCopyAdditions = [int] $AZCopySyncAdditionsRegex.Match($_).Value
$AZCopyDeletions = [int] $AZCopySyncDeletionsRegex.Match($_).Value
$AZCopyAdditions = [int]$AZCopySyncAdditionsRegex.Match($_).Value
$AZCopyDeletions = [int]$AZCopySyncDeletionsRegex.Match($_).Value
if ($AZCopyAdditions -ne 0)
{
@ -212,7 +215,7 @@ function Test-ModsPath
if ($AZCopySyncErrorRegex.Match($_).Value)
{
Write-ToLog -LogMsg ('AZCopy Sync Error! {0}' -f $_)
Write-ToLog -LogMsg ('AZCopy Sync Error! {0}' -f $_)
}
}
}
@ -235,7 +238,7 @@ function Test-ModsPath
# Delete Local Bins that don't exist Externally
foreach ($Bin in $InternalBinsNames)
{
If ($Bin -notin $ExternalBinsNames )
if ($Bin -notin $ExternalBinsNames)
{
$null = (Remove-Item -Path $LocalMods\bins\$Bin -Force -Confirm:$False -ErrorAction SilentlyContinue)
}
@ -271,7 +274,7 @@ function Test-ModsPath
foreach ($Mod in $InternalModsNames)
{
If ($Mod -notin $ExternalModsNames )
if ($Mod -notin $ExternalModsNames)
{
$null = Remove-Item -Path $LocalMods\$Mod -Force -ErrorAction SilentlyContinue
$DeletedMods++

View File

@ -8,7 +8,7 @@ function Test-Network
# Test connectivity during 30 min then timeout
Write-ToLog -LogMsg 'Checking internet connection...' -LogColor 'Yellow'
While ($timeout -lt 1800)
while ($timeout -lt 1800)
{
$URLtoTest = 'https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE'
$URLcontent = ((Invoke-WebRequest -Uri $URLtoTest -UseBasicParsing).content)

View File

@ -1,6 +1,6 @@
# Function to update an App
Function Update-App
function Update-App
{
# Get App Info
[CmdletBinding()]

View File

@ -6,8 +6,10 @@ function Write-ToLog
[CmdletBinding()]
param
(
[string]$LogMsg,
[string]$LogColor = 'White'
[string]
$LogMsg,
[string]
$LogColor = 'White'
)
$Log = ('{0} - {1}' -f (Get-Date -UFormat '%T'), $LogMsg)