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()] [CmdletBinding()]
param( param (
[Alias('S')] [Switch] $Silent = $false, [Alias('S')]
[Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", [Switch]
[Alias('List')] [String] $ListPath, $Silent = $false,
[Alias('Mods')] [String] $ModsPath, [Alias('Path')]
[Alias('AzureBlobURL')] [String] $AzureBlobSASURL, [String]
[Switch] $DoNotUpdate = $false, $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
[Switch] $DisableWAUAutoUpdate = $false, [Alias('List')]
[Switch] $RunOnMetered = $false, [String]
[Switch] $Uninstall = $false, $ListPath,
[Switch] $NoClean = $false, [Alias('Mods')]
[Switch] $DesktopShortcut = $false, [String]
[Switch] $StartMenuShortcut = $false, $ModsPath,
[Switch] $UseWhiteList = $false, [Alias('AzureBlobURL')]
[ValidateSet('Full', 'SuccessOnly', 'None')] [String] $NotificationLevel = 'Full', [String]
[Switch] $UpdatesAtLogon = $false, $AzureBlobSASURL,
[ValidateSet('Daily', 'BiDaily', 'Weekly', 'BiWeekly', 'Monthly', 'Never')] [String] $UpdatesInterval = 'Daily', [Switch]
[DateTime] $UpdatesAtTime = ('06am'), $DoNotUpdate = $false,
[Switch] $BypassListForUsers = $false, [Switch]
[Switch] $InstallUserContext = $false, $DisableWAUAutoUpdate = $false,
[ValidateRange(0, 99)] [int] $MaxLogFiles = 3, [Switch]
[long] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB $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 #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 Write-Host -Object 'Winget is Installed' -ForegroundColor Green
} }
Else else
{ {
Write-Host -Object '-> Winget is not installed:' Write-Host -Object '-> Winget is not installed:'
@ -646,13 +675,9 @@ function Add-Shortcut
param param
( (
$Target, $Target,
$Shortcut, $Shortcut,
$Arguments, $Arguments,
$Icon, $Icon,
$Description $Description
) )
$WScriptShell = New-Object -ComObject WScript.Shell $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") 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)" 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()] [CmdletBinding()]
param( param (
[Switch] $Logs = $False, [Switch]
[Switch] $Help = $False $Logs = $False,
[Switch]
$Help = $False
) )
function Test-WAUisRunning 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' $MessageType = 'info'
Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun Start-NotifTask -Message $Message -MessageType $MessageType -Button1Text $Button1Text -Button1Action $OnClickAction -ButtonDismiss -UserRun
# Sleep until the task is done # Sleep until the task is done
While (Test-WAUisRunning) while (Test-WAUisRunning)
{ {
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
} }

View File

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

View File

@ -4,7 +4,9 @@
$Script:WorkingDir = $PSScriptRoot $Script:WorkingDir = $PSScriptRoot
# Get Functions # Get Functions
Get-ChildItem -Path "$WorkingDir\functions" | ForEach-Object { . $_.FullName } Get-ChildItem -Path "$WorkingDir\functions" | ForEach-Object {
. $_.FullName
}
<# MAIN #> <# MAIN #>
@ -18,55 +20,66 @@ Start-Init
$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 running context and more... #Log running context and more...
if ($IsSystem) { if ($IsSystem)
Write-ToLog '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-ToLog 'Activated WAU GPO Management detected, comparing...' {
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) { Write-ToLog 'Activated WAU GPO Management detected, comparing...'
Write-ToLog 'Changed settings detected and applied' 'Yellow' if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0)
} {
else { Write-ToLog 'Changed settings detected and applied' 'Yellow'
Write-ToLog 'No Changed settings detected' '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. # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles $MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
if ($null -eq $MaxLogFiles) { if ($null -eq $MaxLogFiles)
[int] $MaxLogFiles = 3 {
} [int]$MaxLogFiles = 3
else { }
[int] $MaxLogFiles = $MaxLogFiles else
} {
[int]$MaxLogFiles = $MaxLogFiles
}
# Maximum size of log file. # Maximum size of log file.
$MaxLogSize = $WAUConfig.WAU_MaxLogSize $MaxLogSize = $WAUConfig.WAU_MaxLogSize
if (!$MaxLogSize) { if (!$MaxLogSize)
[long] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB {
} [long]$MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
else { }
[long] $MaxLogSize = $MaxLogSize else
} {
[long]$MaxLogSize = $MaxLogSize
}
#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-ToLog '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
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) { if (!($WAUConfig.WAU_PostUpdateActions -eq 0))
Invoke-PostUpdateActions {
} Invoke-PostUpdateActions
#Run Scope Machine funtion if run as System }
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json" #Run Scope Machine funtion if run as System
Add-ScopeMachine $SettingsPath $SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\defaultState\settings.json"
Add-ScopeMachine $SettingsPath
} }
else { else
Write-ToLog 'Running in User context' {
Write-ToLog 'Running in User context'
} }
#Get Notif Locale function #Get Notif Locale function
@ -74,270 +87,331 @@ $LocaleDisplayName = Get-NotifLocale
Write-ToLog "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)
#Check if Winget is installed and get Winget cmd {
$TestWinget = Get-WingetCmd #Check if Winget is installed and get Winget cmd
$TestWinget = Get-WingetCmd
if ($TestWinget) { if ($TestWinget)
#Get Current Version {
$WAUCurrentVersion = $WAUConfig.DisplayVersion #Get Current Version
Write-ToLog "WAU current version: $WAUCurrentVersion" $WAUCurrentVersion = $WAUConfig.DisplayVersion
if ($IsSystem) { Write-ToLog "WAU current version: $WAUCurrentVersion"
#Check if WAU update feature is enabled or not if run as System if ($IsSystem)
$WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate {
#If yes then check WAU update if run as System #Check if WAU update feature is enabled or not if run as System
if ($WAUDisableAutoUpdate -eq 1) { $WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate
Write-ToLog 'WAU AutoUpdate is Disabled.' 'Gray' #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 { else
Write-ToLog 'WAU AutoUpdate is Enabled.' 'Green' {
#Get Available Version Write-ToLog 'WAU is up to date.' 'Green'
$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'
}
} }
}
#Delete previous list_/winget_error (if they exist) if run as System #Delete previous list_/winget_error (if they exist) if run as System
if (Test-Path -Path "$WorkingDir\logs\error.txt") { if (Test-Path -Path "$WorkingDir\logs\error.txt")
Remove-Item -Path "$WorkingDir\logs\error.txt" -Force {
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 #Get External ModsPath if run as System
if ($WAUConfig.WAU_ListPath) { if ($WAUConfig.WAU_ModsPath)
$ListPathClean = $($WAUConfig.WAU_ListPath.TrimEnd(' ', '\', '/')) {
Write-ToLog "WAU uses External Lists from: $ListPathClean" $ModsPathClean = $($WAUConfig.WAU_ModsPath.TrimEnd(' ', '\', '/'))
if ($ListPathClean -ne 'GPO') { Write-ToLog "WAU uses External Mods from: $ModsPathClean"
$NewList = Test-ListPath $ListPathClean $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation.TrimEnd(' ', '\') if ($WAUConfig.WAU_AzureBlobSASURL)
if ($ReachNoPath) { {
Write-ToLog "Couldn't reach/find/compare/copy from $ListPathClean..." 'Red' $NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\') $WAUConfig.WAU_AzureBlobSASURL.TrimEnd(' ')
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
}
}
}
} }
else
#Get External ModsPath if run as System {
if ($WAUConfig.WAU_ModsPath) { $NewMods, $DeletedMods = Test-ModsPath $ModsPathClean $WAUConfig.InstallLocation.TrimEnd(' ', '\')
$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'
}
} }
if ($ReachNoPath)
#Test if _WAU-mods.ps1 exist: Mods for WAU (if Network is active/any Winget is installed/running as SYSTEM) {
$Mods = "$WorkingDir\mods" Write-ToLog "Couldn't reach/find/compare/copy from $ModsPathClean..." 'Red'
if (Test-Path -Path "$Mods\_WAU-mods.ps1") { $Script:ReachNoPath = $False
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 ($NewMods -gt 0)
} {
Write-ToLog "$NewMods newer Mods downloaded/copied to local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Yellow'
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
} }
else { else
$BlackList = $toSkip.GetUpperBound(0) {
if ($null -eq $BlackList) { if (Test-Path -Path "$WorkingDir\mods\*.ps1")
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 Write-ToLog 'Mods are up to date.' 'Green'
Exit 1 }
} else
$toSkip = $toSkip.Data {
Write-ToLog 'No Mods are implemented...' 'Yellow'
}
} }
} if ($DeletedMods -gt 0)
{
#Get outdated Winget packages Write-ToLog "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Red'
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 #Test if _WAU-mods.ps1 exist: Mods for WAU (if Network is active/any Winget is installed/running as SYSTEM)
$Script:InstallOK = 0 $Mods = "$WorkingDir\mods"
if (Test-Path -Path "$Mods\_WAU-mods.ps1")
#Trick under user context when -BypassListForUsers is used {
if ($IsSystem -eq $false -and $WAUConfig.WAU_BypassListForUsers -eq 1) { Write-ToLog 'Running Mods for WAU...' 'Yellow'
Write-ToLog 'Bypass system list in user context is Enabled.' & "$Mods\_WAU-mods.ps1"
$UseWhiteList = $false $ModsExitCode = $LASTEXITCODE
$toSkip = $null #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 if ($($WAUConfig.WAU_ListPath) -eq 'GPO')
foreach ($app in $outdated) { {
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne 'Unknown') { $Script:GPOList = $True
Update-App $app }
}
#if current app version is unknown #Get White or Black list
elseif ($($app.Version) -eq 'Unknown') { if ($WAUConfig.WAU_UseWhiteList -eq 1)
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray' {
} Write-ToLog 'WAU uses White List config'
#if app is in "excluded list" $toUpdate = Get-IncludedApps
else { $UseWhiteList = $true
Write-ToLog "$($app.Name) : Skipped upgrade because it is not in the included app list" 'Gray' }
} 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 $toUpdate = $toUpdate.Data
else { }
#For each app, notify and update else
foreach ($app in $outdated) { {
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne 'Unknown') { $BlackList = $toSkip.GetUpperBound(0)
Update-App $app if ($null -eq $BlackList)
} {
#if current app version is unknown Write-ToLog "Critical: Blacklist doesn't exist in GPO, exiting..." 'Red'
elseif ($($app.Version) -eq 'Unknown') { New-Item -Path "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" 'Gray' exit 1
}
#if app is in "excluded list"
else {
Write-ToLog "$($app.Name) : Skipped upgrade because it is in the excluded app list" 'Gray'
}
}
} }
$toSkip = $toSkip.Data
}
}
if ($InstallOK -gt 0) { #Get outdated Winget packages
Write-ToLog "$InstallOK apps updated ! No more update." 'Green' 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 Black List or default
if ($InstallOK -eq 0 -or !$InstallOK) { else
Write-ToLog 'No new update.' 'Green' {
} #For each app, notify and update
foreach ($app in $outdated)
#Check if any user is logged on if System and run User task (if installed) {
if ($IsSystem) { if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne 'Unknown')
#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) Update-App $app
If ($explorerprocesses.Count -eq 0) { }
Write-ToLog 'No explorer process found / Nobody interactively logged on...' #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 if ($InstallOK -gt 0)
Write-ToLog 'User logged on, get a list of installed Winget apps in System context...' {
Get-WingetSystemApps Write-ToLog "$InstallOK apps updated ! No more update." 'Green'
}
}
#Run user context scheduled task if ($InstallOK -eq 0 -or !$InstallOK)
Write-ToLog 'Starting WAU in User context' {
Start-ScheduledTask -TaskName $UserScheduledTask.TaskName -ErrorAction SilentlyContinue Write-ToLog 'No new update.' 'Green'
Exit 0 }
}
elseif (!$UserScheduledTask) { #Check if any user is logged on if System and run User task (if installed)
Write-ToLog 'User context execution not 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
} }
} elseif (!$UserScheduledTask)
} {
else { Write-ToLog 'User context execution not installed...'
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 }
} 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 #End

View File

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

View File

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

View File

@ -1,12 +1,14 @@
Function Confirm-Installation function Confirm-Installation
{ {
# Set json export file # Set json export file
[CmdletBinding()] [CmdletBinding()]
param param
( (
[string]$AppName, [string]
[string]$AppVer $AppName,
[string]
$AppVer
) )
$JsonFile = ('{0}\Config\InstalledApps.json' -f $WorkingDir) $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 to get AZCopy, if it doesn't exist and update it, if it does
Function Get-AZCopy function Get-AZCopy
{ {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[string]$WingetUpdatePath [string]
$WingetUpdatePath
) )
$AZCopyLink = (Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue).headers.location $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 = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value $AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value
Write-ToLog -LogMsg ('AZCopy version {0} found' -f $AZCopyCurrentVersion) Write-ToLog -LogMsg ('AZCopy version {0} found' -f $AZCopyCurrentVersion)
} }
else else
{ {
Write-ToLog -LogMsg 'AZCopy not already installed' Write-ToLog -LogMsg '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-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)) $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) $null = (Expand-Archive -Path ('{0}\azcopyv10.zip' -f $WingetUpdatePath) -DestinationPath $WingetUpdatePath -Force -Confirm:$false)
$AZCopyPathSearch = (Resolve-Path -Path ('{0}\azcopy_*' -f $WingetUpdatePath)) $AZCopyPathSearch = (Resolve-Path -Path ('{0}\azcopy_*' -f $WingetUpdatePath))
@ -46,13 +47,13 @@ Function Get-AZCopy
$AZCopyEXEPath = $AZCopyPathSearch $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) $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 $AZCopyEXEPath -Recurse -Force -Confirm:$false)
$null = (Remove-Item -Path ('{0}\azcopyv10.zip' -f $WingetUpdatePath) -Force -Confirm:$false) $null = (Remove-Item -Path ('{0}\azcopyv10.zip' -f $WingetUpdatePath) -Force -Confirm:$false)
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v $AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
$AZCopyCurrentVersion = $AZCopyVersionRegex.Match($AZCopyCurrentVersion).Value $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 # Get the winget App Information
Function Get-AppInfo function Get-AppInfo
{ {
# Get AppID Info # Get AppID Info
[CmdletBinding()] [CmdletBinding()]
param param
( (
[string]$AppID [string]
$AppID
) )
$String = (& $winget show $AppID --accept-source-agreements -s winget | Out-String) $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 to get the locale file for notifications
Function Get-NotifLocale { function Get-NotifLocale
{
# Get OS locale # Get OS locale
$OSLocale = (Get-UICulture).Parent $OSLocale = (Get-UICulture).Parent
# Test if OS locale notif file exists # Test if OS locale notif file exists
$TestOSLocalPath = ('{0}\locale\{1}.xml' -f $WorkingDir, $OSLocale.Name) $TestOSLocalPath = ('{0}\locale\{1}.xml' -f $WorkingDir, $OSLocale.Name)
# Set OS Local if file exists # Set OS Local if file exists
if (Test-Path -Path $TestOSLocalPath -ErrorAction SilentlyContinue) { if (Test-Path -Path $TestOSLocalPath -ErrorAction SilentlyContinue)
$LocaleDisplayName = $OSLocale.DisplayName {
$LocaleFile = $TestOSLocalPath $LocaleDisplayName = $OSLocale.DisplayName
} $LocaleFile = $TestOSLocalPath
else { }
# Set English if file doesn't exist else
$LocaleDisplayName = 'English' {
$LocaleFile = ('{0}\locale\en.xml' -f $WorkingDir) # Set English if file doesn't exist
} $LocaleDisplayName = 'English'
$LocaleFile = ('{0}\locale\en.xml' -f $WorkingDir)
}
# Get locale XML file content # Get locale XML file content
[xml]$Script:NotifLocale = (Get-Content -Path $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue) [xml]$Script:NotifLocale = (Get-Content -Path $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue)
# Rerturn langague display name # Rerturn langague display name
Return $LocaleDisplayName return $LocaleDisplayName
} }

View File

@ -1,6 +1,6 @@
# Function to get the Domain/Local Policies (GPO) # Function to get the Domain/Local Policies (GPO)
Function Get-Policies function Get-Policies
{ {
# Get WAU Policies and set the Configurations Registry Accordingly # Get WAU Policies and set the Configurations Registry Accordingly
$WAUPolicies = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate' -ErrorAction SilentlyContinue) $WAUPolicies = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate' -ErrorAction SilentlyContinue)
@ -196,7 +196,8 @@ Function Get-Policies
$task = $folder.GetTask('Winget-AutoUpdate') $task = $folder.GetTask('Winget-AutoUpdate')
$definition = $task.Definition $definition = $task.Definition
$null = $definition.Triggers.Count $null = $definition.Triggers.Count
switch ($($WAUPolicies.WAU_UpdatesInterval)) { switch ($($WAUPolicies.WAU_UpdatesInterval))
{
'Daily' 'Daily'
{ {
$tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) $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 to get the winget command regarding execution context (User, System...)
Function Get-WingetCmd { function Get-WingetCmd
{
# Get WinGet Path (if Admin context) # Get WinGet Path (if Admin context)
# Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard) # 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') }) $ResolveWingetPath = (Resolve-Path -Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object -Property {
[version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1')
})
if ($ResolveWingetPath) { if ($ResolveWingetPath)
# If multiple version, pick last one {
$WingetPath = $ResolveWingetPath[-1].Path # If multiple version, pick last one
} $WingetPath = $ResolveWingetPath[-1].Path
}
#If running under System or Admin context obtain Winget from Program Files #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 ((([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) if (Test-Path -Path ('{0}\winget.exe' -f $WingetPath) -ErrorAction SilentlyContinue)
} {
}else{ $Script:Winget = ('{0}\winget.exe' -f $WingetPath)
#Get Winget Location in User context }
$WingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue) }
else
{
#Get Winget Location in User context
$WingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue)
if ($WingetCmd) { if ($WingetCmd)
$Script:Winget = $WingetCmd.Source {
} $Script:Winget = $WingetCmd.Source
} }
}
If(!($Script:Winget)){ if (!($Script:Winget))
Write-ToLog 'Winget not installed or detected !' 'Red' {
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) # Run winget to list apps and accept source agrements (necessary on first run)
$null = (& $Winget list --accept-source-agreements -s winget) $null = (& $Winget list --accept-source-agreements -s winget)
# Log Winget installed version # Log Winget installed version
$WingetVer = & $Winget --version $WingetVer = & $Winget --version
Write-ToLog ('Winget Version: {0}' -f $WingetVer) 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 # Now cycle in real package and split accordingly
$upgradeList = @() $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 $line = $lines[$i] -replace '[\u2026]', ' ' #Fix "..." in long names

View File

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

View File

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

View File

@ -26,7 +26,7 @@ function Invoke-PostUpdateActions
$Visual2022 = 'Microsoft Visual C++ 2015-2022 Redistributable*' $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 { $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 $_.GetValue('DisplayName') -like $Visual2019 -or $_.GetValue('DisplayName') -like $Visual2022
}) })
# If not installed, install # If not installed, install
if (!($path)) if (!($path))
@ -69,11 +69,11 @@ function Invoke-PostUpdateActions
} }
# Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0 # 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' Write-ToLog -LogMsg '-> WinGet is Installed/up to date' -LogColor 'green'
} }
Else else
{ {
# Download WinGet MSIXBundle # Download WinGet MSIXBundle
Write-ToLog -LogMsg '-> Not installed/up to date. Downloading WinGet...' Write-ToLog -LogMsg '-> Not installed/up to date. Downloading WinGet...'

View File

@ -3,17 +3,27 @@
function Start-NotifTask function Start-NotifTask
{ {
[CmdletBinding()] [CmdletBinding()]
param( param (
[String]$Title = 'Winget-AutoUpdate', [String]
[String]$Message, $Title = 'Winget-AutoUpdate',
[String]$MessageType, [String]
[String]$Balise = 'WAU', $Message,
[String]$OnClickAction, [String]
[String]$Body, $MessageType,
[String]$Button1Text, [String]
[String]$Button1Action, $Balise = 'WAU',
[Switch]$ButtonDismiss = $false, [String]
[Switch]$UserRun = $false $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)) 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()] [CmdletBinding()]
param param
( (
[string]$ListPath, [string]
[string]$UseWhiteList, $ListPath,
[string]$WingetUpdatePath [string]
$UseWhiteList,
[string]
$WingetUpdatePath
) )
if ($UseWhiteList) if ($UseWhiteList)

View File

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

View File

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

View File

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

View File

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

View File

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