parent
6c118323f9
commit
9d6fa35138
|
@ -150,14 +150,14 @@ param (
|
|||
function Install-Prerequisites
|
||||
{
|
||||
Write-Host -Object "`nChecking prerequisites..." -ForegroundColor Yellow
|
||||
|
||||
|
||||
#Check if Visual C++ 2019 or 2022 installed
|
||||
$Visual2019 = 'Microsoft Visual C++ 2015-2019 Redistributable*'
|
||||
$Visual2022 = 'Microsoft Visual C++ 2015-2022 Redistributable*'
|
||||
$path = Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object -FilterScript {
|
||||
$_.GetValue('DisplayName') -like $Visual2019 -or $_.GetValue('DisplayName') -like $Visual2022
|
||||
}
|
||||
|
||||
|
||||
#If not installed, ask for installation
|
||||
if (!($path))
|
||||
{
|
||||
|
@ -225,12 +225,12 @@ function Install-Prerequisites
|
|||
function Install-WinGet
|
||||
{
|
||||
Write-Host -Object "`nChecking if Winget is installed" -ForegroundColor Yellow
|
||||
|
||||
|
||||
#Check Package Install
|
||||
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object -FilterScript {
|
||||
$_.DisplayName -eq 'Microsoft.DesktopAppInstaller'
|
||||
}
|
||||
|
||||
|
||||
#Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
|
||||
if ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
|
||||
{
|
||||
|
@ -239,13 +239,13 @@ function Install-WinGet
|
|||
else
|
||||
{
|
||||
Write-Host -Object '-> Winget is not installed:'
|
||||
|
||||
|
||||
#Check if $WingetUpdatePath exist
|
||||
if (!(Test-Path $WingetUpdatePath))
|
||||
{
|
||||
$null = New-Item -ItemType Directory -Force -Path $WingetUpdatePath
|
||||
}
|
||||
|
||||
|
||||
#Downloading and Installing Dependencies in SYSTEM context
|
||||
if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7'))
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ function Install-WinGet
|
|||
Remove-Item -Path $UiXamlZip -Force
|
||||
Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse
|
||||
}
|
||||
|
||||
|
||||
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop'))
|
||||
{
|
||||
Write-Host -Object '-> Downloading Microsoft.VCLibs.140.00.UWPDesktop...'
|
||||
|
@ -286,13 +286,13 @@ function Install-WinGet
|
|||
}
|
||||
Remove-Item -Path $VCLibsFile -Force
|
||||
}
|
||||
|
||||
|
||||
#Download WinGet MSIXBundle
|
||||
Write-Host -Object '-> Downloading Winget MSIXBundle for App Installer...'
|
||||
$WinGetURL = 'https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
|
||||
$WebClient = New-Object -TypeName System.Net.WebClient
|
||||
$WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||
|
||||
|
||||
#Install WinGet MSIXBundle in SYSTEM context
|
||||
try
|
||||
{
|
||||
|
@ -304,7 +304,7 @@ function Install-WinGet
|
|||
{
|
||||
Write-Host -Object 'Failed to intall Winget MSIXBundle for App Installer...' -ForegroundColor Red
|
||||
}
|
||||
|
||||
|
||||
#Remove WinGet MSIXBundle
|
||||
Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ function Install-WinGet
|
|||
function Install-WingetAutoUpdate
|
||||
{
|
||||
Write-Host -Object "`nInstalling WAU..." -ForegroundColor Yellow
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
#Copy files to location (and clean old install)
|
||||
|
@ -334,7 +334,7 @@ function Install-WingetAutoUpdate
|
|||
}
|
||||
}
|
||||
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
#White List or Black List apps
|
||||
if ($UseWhiteList)
|
||||
{
|
||||
|
@ -378,11 +378,11 @@ function Install-WingetAutoUpdate
|
|||
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Set dummy regkeys for notification name and icon
|
||||
$null = & "$env:windir\system32\reg.exe" add 'HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification' /v DisplayName /t REG_EXPAND_SZ /d 'Application Update' /f
|
||||
$null = & "$env:windir\system32\reg.exe" add 'HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification' /v IconUri /t REG_EXPAND_SZ /d %SystemRoot%\system32\@WindowsUpdateToastIcon.png /f
|
||||
|
||||
|
||||
# Settings for the scheduled task for Updates
|
||||
$taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""
|
||||
$taskTriggers = @()
|
||||
|
@ -412,7 +412,7 @@ function Install-WingetAutoUpdate
|
|||
}
|
||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
|
||||
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
|
||||
|
||||
|
||||
# Set up the task, and register it
|
||||
if ($taskTriggers)
|
||||
{
|
||||
|
@ -422,30 +422,30 @@ function Install-WingetAutoUpdate
|
|||
{
|
||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||
}
|
||||
|
||||
|
||||
$null = Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force
|
||||
|
||||
|
||||
if ($InstallUserContext)
|
||||
{
|
||||
# Settings for the scheduled task in User context
|
||||
$taskAction = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`""
|
||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
||||
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
|
||||
|
||||
|
||||
# Set up the task for user apps
|
||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||
$null = Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force
|
||||
}
|
||||
|
||||
|
||||
# Settings for the scheduled task for Notifications
|
||||
$taskAction = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
||||
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
|
||||
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
|
||||
|
||||
|
||||
# Set up the task, and register it
|
||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||
$null = Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force
|
||||
|
||||
|
||||
#Set task readable/runnable for all users
|
||||
$scheduler = New-Object -ComObject 'Schedule.Service'
|
||||
$scheduler.Connect()
|
||||
|
@ -453,7 +453,7 @@ function Install-WingetAutoUpdate
|
|||
$sec = $task.GetSecurityDescriptor(0xF)
|
||||
$sec = $sec + '(A;;GRGX;;;AU)'
|
||||
$task.SetSecurityDescriptor($sec, 0)
|
||||
|
||||
|
||||
# Configure Reg Key
|
||||
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate'
|
||||
$null = New-Item $regPath -Force
|
||||
|
@ -507,11 +507,11 @@ function Install-WingetAutoUpdate
|
|||
{
|
||||
$null = New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value 1 -PropertyType DWord -Force
|
||||
}
|
||||
|
||||
|
||||
#Log file and symlink initialization
|
||||
. "$WingetUpdatePath\functions\Start-Init.ps1"
|
||||
Start-Init
|
||||
|
||||
|
||||
#Security check
|
||||
Write-Host -Object "`nChecking Mods Directory:" -ForegroundColor Yellow
|
||||
. "$WingetUpdatePath\functions\Invoke-ModsProtect.ps1"
|
||||
|
@ -528,7 +528,7 @@ function Install-WingetAutoUpdate
|
|||
{
|
||||
Write-Host -Object "Error: The mods directory couldn't be verified as secured!`n" -ForegroundColor Red
|
||||
}
|
||||
|
||||
|
||||
#Create Shortcuts
|
||||
if ($StartMenuShortcut)
|
||||
{
|
||||
|
@ -540,15 +540,15 @@ function Install-WingetAutoUpdate
|
|||
Add-Shortcut 'wscript.exe' "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" 'Open existing WAU logs...'
|
||||
Add-Shortcut 'wscript.exe' "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" 'Help for WAU...'
|
||||
}
|
||||
|
||||
|
||||
if ($DesktopShortcut)
|
||||
{
|
||||
Add-Shortcut 'wscript.exe' "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" 'Manual start of Winget-AutoUpdate (WAU)...'
|
||||
}
|
||||
|
||||
|
||||
Write-Host -Object 'WAU Installation succeeded!' -ForegroundColor Green
|
||||
Start-Sleep -Seconds 1
|
||||
|
||||
|
||||
#Run Winget ?
|
||||
Start-WingetAutoUpdate
|
||||
}
|
||||
|
@ -563,12 +563,12 @@ function Install-WingetAutoUpdate
|
|||
function Uninstall-WingetAutoUpdate
|
||||
{
|
||||
Write-Host -Object "`nUninstalling WAU..." -ForegroundColor Yellow
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
#Get registry install location
|
||||
$InstallLocation = Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\' -Name InstallLocation
|
||||
|
||||
|
||||
#Check if installed location exists and delete
|
||||
if (Test-Path ($InstallLocation))
|
||||
{
|
||||
|
@ -594,17 +594,17 @@ function Uninstall-WingetAutoUpdate
|
|||
Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false
|
||||
$null = & "$env:windir\system32\reg.exe" delete 'HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification' /f
|
||||
$null = & "$env:windir\system32\reg.exe" delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate' /f
|
||||
|
||||
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)"))
|
||||
{
|
||||
$null = Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force
|
||||
}
|
||||
|
||||
|
||||
if ((Test-Path -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"))
|
||||
{
|
||||
$null = Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force
|
||||
}
|
||||
|
||||
|
||||
Write-Host -Object 'Uninstallation succeeded!' -ForegroundColor Green
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ else
|
|||
{
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
|
||||
|
||||
# Test if there was a list_/winget_error
|
||||
if (Test-Path -Path ('{0}\logs\error.txt' -f $WorkingDir) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
|
|
|
@ -35,10 +35,10 @@ Write-Host -Object "`t________________________________________________________`n
|
|||
try
|
||||
{
|
||||
Write-Host -Object 'Uninstalling WAU...' -ForegroundColor Yellow
|
||||
|
||||
|
||||
# Get registry install location
|
||||
$InstallLocation = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\' -Name InstallLocation)
|
||||
|
||||
|
||||
# Check if installed location exists and delete
|
||||
if (Test-Path -Path ($InstallLocation))
|
||||
{
|
||||
|
@ -56,22 +56,22 @@ try
|
|||
$null = (Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false)
|
||||
$null = & "$env:windir\system32\reg.exe" delete 'HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification' /f
|
||||
$null = & "$env:windir\system32\reg.exe" delete 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate' /f
|
||||
|
||||
|
||||
if (Test-Path -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate' -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$null = & "$env:windir\system32\reg.exe" delete 'HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate' /f
|
||||
}
|
||||
|
||||
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)"))
|
||||
{
|
||||
$null = (Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force -Confirm:$false)
|
||||
}
|
||||
|
||||
|
||||
if ((Test-Path -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"))
|
||||
{
|
||||
$null = (Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force -Confirm:$false)
|
||||
}
|
||||
|
||||
|
||||
# Remove Intune Logs if they are existing
|
||||
if (Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log")
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ try
|
|||
{
|
||||
$null = (Remove-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -Force -Confirm:$false -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
Write-Host -Object 'Uninstallation succeeded!' -ForegroundColor Green
|
||||
}
|
||||
else
|
||||
|
|
|
@ -23,7 +23,7 @@ $Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Cu
|
|||
if ($IsSystem)
|
||||
{
|
||||
Write-ToLog 'Running in System context'
|
||||
|
||||
|
||||
#Get and set Domain/Local Policies (GPO)
|
||||
$ActivateGPOManagement, $ChangedSettings = Get-Policies
|
||||
if ($ActivateGPOManagement)
|
||||
|
@ -38,7 +38,7 @@ if ($IsSystem)
|
|||
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)
|
||||
|
@ -49,7 +49,7 @@ if ($IsSystem)
|
|||
{
|
||||
[int]$MaxLogFiles = $MaxLogFiles
|
||||
}
|
||||
|
||||
|
||||
# Maximum size of log file.
|
||||
$MaxLogSize = $WAUConfig.WAU_MaxLogSize
|
||||
if (!$MaxLogSize)
|
||||
|
@ -60,14 +60,14 @@ if ($IsSystem)
|
|||
{
|
||||
[long]$MaxLogSize = $MaxLogSize
|
||||
}
|
||||
|
||||
|
||||
#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))
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ if (Test-Network)
|
|||
{
|
||||
#Check if Winget is installed and get Winget cmd
|
||||
$TestWinget = Get-WingetCmd
|
||||
|
||||
|
||||
if ($TestWinget)
|
||||
{
|
||||
#Get Current Version
|
||||
|
@ -123,13 +123,13 @@ if (Test-Network)
|
|||
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
|
||||
}
|
||||
|
||||
|
||||
#Get External ListPath if run as System
|
||||
if ($WAUConfig.WAU_ListPath)
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ if (Test-Network)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Get External ModsPath if run as System
|
||||
if ($WAUConfig.WAU_ModsPath)
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ if (Test-Network)
|
|||
Write-ToLog "$DeletedMods Mods deleted (not externally managed) from local path: $($WAUConfig.InstallLocation.TrimEnd(' ', '\'))\mods" 'Red'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#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")
|
||||
|
@ -235,14 +235,14 @@ if (Test-Network)
|
|||
exit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($($WAUConfig.WAU_ListPath) -eq 'GPO')
|
||||
{
|
||||
$Script:GPOList = $True
|
||||
}
|
||||
|
||||
|
||||
#Get White or Black list
|
||||
if ($WAUConfig.WAU_UseWhiteList -eq 1)
|
||||
{
|
||||
|
@ -255,7 +255,7 @@ if (Test-Network)
|
|||
Write-ToLog 'WAU uses Black List config'
|
||||
$toSkip = Get-ExcludedApps
|
||||
}
|
||||
|
||||
|
||||
#Fix and count the array if GPO List as ERROR handling!
|
||||
if ($GPOList)
|
||||
{
|
||||
|
@ -282,18 +282,18 @@ if (Test-Network)
|
|||
$toSkip = $toSkip.Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -305,10 +305,10 @@ if (Test-Network)
|
|||
$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)
|
||||
{
|
||||
|
@ -316,7 +316,7 @@ if (Test-Network)
|
|||
$UseWhiteList = $false
|
||||
$toSkip = $null
|
||||
}
|
||||
|
||||
|
||||
#If White List
|
||||
if ($UseWhiteList)
|
||||
{
|
||||
|
@ -361,18 +361,18 @@ if (Test-Network)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($InstallOK -gt 0)
|
||||
{
|
||||
Write-ToLog "$InstallOK apps updated ! No more update." 'Green'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -388,11 +388,11 @@ if (Test-Network)
|
|||
$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
|
||||
|
|
|
@ -7,20 +7,20 @@ function Add-ScopeMachine
|
|||
[string]
|
||||
$SettingsPath
|
||||
)
|
||||
|
||||
|
||||
if (Test-Path -Path $SettingsPath -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ConfigFile = (Get-Content -Path $SettingsPath -ErrorAction SilentlyContinue | Where-Object -FilterScript {
|
||||
($_ -notmatch '//')
|
||||
} | ConvertFrom-Json)
|
||||
}
|
||||
|
||||
|
||||
if (!$ConfigFile)
|
||||
{
|
||||
$ConfigFile = @{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($ConfigFile.installBehavior.preferences.scope)
|
||||
{
|
||||
$ConfigFile.installBehavior.preferences.scope = 'Machine'
|
||||
|
@ -35,6 +35,6 @@ function Add-ScopeMachine
|
|||
}))
|
||||
$null = (Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force)
|
||||
}
|
||||
|
||||
|
||||
$null = ($ConfigFile | ConvertTo-Json | Out-File -FilePath $SettingsPath -Encoding utf8 -Force -Confirm:$false)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ function Add-Shortcut
|
|||
[string]
|
||||
$Description
|
||||
)
|
||||
|
||||
|
||||
$WScriptShell = (New-Object -ComObject WScript.Shell)
|
||||
$Shortcut = $WScriptShell.CreateShortcut($Shortcut)
|
||||
$Shortcut.TargetPath = $Target
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function Confirm-Installation
|
||||
{
|
||||
# Set json export file
|
||||
|
||||
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
|
@ -10,26 +10,26 @@ function Confirm-Installation
|
|||
[string]
|
||||
$AppVer
|
||||
)
|
||||
|
||||
|
||||
$JsonFile = ('{0}\Config\InstalledApps.json' -f $WorkingDir)
|
||||
|
||||
|
||||
# Get installed apps and version in json file
|
||||
$null = (& $Winget export -s winget -o $JsonFile --include-versions)
|
||||
|
||||
|
||||
# Get json content
|
||||
$Json = (Get-Content -Path $JsonFile -Raw | ConvertFrom-Json)
|
||||
|
||||
|
||||
# Get apps and version in hashtable
|
||||
$Packages = $Json.Sources.Packages
|
||||
|
||||
|
||||
# Remove json file
|
||||
$null = (Remove-Item -Path $JsonFile -Force -Confirm:$false -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Search for specific app and version
|
||||
$Apps = $Packages | Where-Object -FilterScript {
|
||||
($_.PackageIdentifier -eq $AppName -and $_.Version -like ('{0}*' -f $AppVer))
|
||||
}
|
||||
|
||||
|
||||
if ($Apps)
|
||||
{
|
||||
return $true
|
||||
|
|
|
@ -8,16 +8,16 @@ function Get-AZCopy
|
|||
[string]
|
||||
$WingetUpdatePath
|
||||
)
|
||||
|
||||
|
||||
$AZCopyLink = (Invoke-WebRequest -Uri https://aka.ms/downloadazcopy-v10-windows -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue).headers.location
|
||||
$AZCopyVersionRegex = [regex]::new('(\d+\.\d+\.\d+)')
|
||||
$AZCopyLatestVersion = $AZCopyVersionRegex.Match($AZCopyLink).Value
|
||||
|
||||
|
||||
if ($null -eq $AZCopyLatestVersion -or '' -eq $AZCopyLatestVersion)
|
||||
{
|
||||
$AZCopyLatestVersion = '0.0.0'
|
||||
}
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\azcopy.exe' -f $WingetUpdatePath) -PathType Leaf -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$AZCopyCurrentVersion = & "$WingetUpdatePath\azcopy.exe" -v
|
||||
|
@ -29,7 +29,7 @@ function Get-AZCopy
|
|||
Write-ToLog -LogMsg 'AZCopy not already installed'
|
||||
$AZCopyCurrentVersion = '0.0.0'
|
||||
}
|
||||
|
||||
|
||||
if (([version]$AZCopyCurrentVersion) -lt ([version]$AZCopyLatestVersion))
|
||||
{
|
||||
Write-ToLog -LogMsg ('Installing version {0} of AZCopy' -f $AZCopyLatestVersion)
|
||||
|
@ -37,7 +37,7 @@ function Get-AZCopy
|
|||
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))
|
||||
|
||||
|
||||
if ($AZCopyPathSearch -is [array])
|
||||
{
|
||||
$AZCopyEXEPath = $AZCopyPathSearch[$AZCopyPathSearch.Length - 1]
|
||||
|
@ -46,7 +46,7 @@ function Get-AZCopy
|
|||
{
|
||||
$AZCopyEXEPath = $AZCopyPathSearch
|
||||
}
|
||||
|
||||
|
||||
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'
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
function Get-AppInfo
|
||||
{
|
||||
# Get AppID Info
|
||||
# Get AppID Info
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[string]
|
||||
$AppID
|
||||
)
|
||||
|
||||
|
||||
$String = (& $winget show $AppID --accept-source-agreements -s winget | Out-String)
|
||||
# Search for Release Note info
|
||||
$ReleaseNote = [regex]::match($String, '(?<=Release Notes Url: )(.*)(?=\n)').Groups[0].Value
|
||||
|
||||
|
||||
# Return Release Note
|
||||
return $ReleaseNote
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ function Get-ExcludedApps
|
|||
if (Test-Path -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList' -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList\'
|
||||
|
||||
|
||||
$ValueNames = (Get-Item -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList').Property
|
||||
|
||||
|
||||
foreach ($ValueName in $ValueNames)
|
||||
{
|
||||
$AppIDs = [Microsoft.Win32.Registry]::GetValue($Key, $ValueName, $false)
|
||||
|
@ -19,7 +19,7 @@ function Get-ExcludedApps
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $AppIDs
|
||||
}
|
||||
elseif (Test-Path -Path ('{0}\excluded_apps.txt' -f $WorkingDir) -ErrorAction SilentlyContinue)
|
||||
|
|
|
@ -8,7 +8,7 @@ function Get-IncludedApps
|
|||
{
|
||||
$Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\WhiteList\'
|
||||
$ValueNames = (Get-Item -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\WhiteList').Property
|
||||
|
||||
|
||||
foreach ($ValueName in $ValueNames)
|
||||
{
|
||||
$AppIDs = [Microsoft.Win32.Registry]::GetValue($Key, $ValueName, $false)
|
||||
|
@ -18,7 +18,7 @@ function Get-IncludedApps
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $AppIDs
|
||||
}
|
||||
elseif (Test-Path -Path ('{0}\included_apps.txt' -f $WorkingDir) -ErrorAction SilentlyContinue)
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
function Get-NotifLocale
|
||||
{
|
||||
|
||||
|
||||
# Get OS locale
|
||||
$OSLocale = (Get-UICulture).Parent
|
||||
|
||||
|
||||
# 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)
|
||||
{
|
||||
|
@ -21,11 +21,11 @@ function Get-NotifLocale
|
|||
$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)
|
||||
|
||||
|
||||
# Rerturn langague display name
|
||||
return $LocaleDisplayName
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ function Get-Policies
|
|||
{
|
||||
# Get WAU Policies and set the Configurations Registry Accordingly
|
||||
$WAUPolicies = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate' -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
if ($WAUPolicies)
|
||||
{
|
||||
if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1))
|
||||
{
|
||||
$ChangedSettings = 0
|
||||
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate'
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
@ -22,7 +22,7 @@ function Get-Policies
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUPolicies.WAU_DisableAutoUpdate) -ne $($WAUConfig.WAU_DisableAutoUpdate)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
@ -33,7 +33,7 @@ function Get-Policies
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_DoNotRunOnMetered) -and ($($WAUPolicies.WAU_DoNotRunOnMetered) -ne $($WAUConfig.WAU_DoNotRunOnMetered)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_DoNotRunOnMetered -Value $($WAUPolicies.WAU_DoNotRunOnMetered) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
@ -44,7 +44,7 @@ function Get-Policies
|
|||
$null = (New-ItemProperty -Path $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UpdatePrerelease) -and ($($WAUPolicies.WAU_UpdatePrerelease) -ne $($WAUConfig.WAU_UpdatePrerelease)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatePrerelease -Value $($WAUPolicies.WAU_UpdatePrerelease) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
@ -55,7 +55,7 @@ function Get-Policies
|
|||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUPolicies.WAU_UseWhiteList) -ne $($WAUConfig.WAU_UseWhiteList)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UseWhiteList -Value $($WAUPolicies.WAU_UseWhiteList) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
@ -66,7 +66,7 @@ function Get-Policies
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath) -ne $($WAUConfig.WAU_ListPath)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(' ', '\', '/')) -Force -Confirm:$false)
|
||||
|
@ -77,7 +77,7 @@ function Get-Policies
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name WAU_ListPath -Force -ErrorAction SilentlyContinue -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath) -ne $($WAUConfig.WAU_ModsPath)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(' ', '\', '/')) -Force -Confirm:$false)
|
||||
|
@ -98,7 +98,7 @@ function Get-Policies
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name WAU_AzureBlobSASURL -Force -ErrorAction SilentlyContinue -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_NotificationLevel) -and ($($WAUPolicies.WAU_NotificationLevel) -ne $($WAUConfig.WAU_NotificationLevel)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_NotificationLevel -Value $($WAUPolicies.WAU_NotificationLevel) -Force -Confirm:$false)
|
||||
|
@ -109,7 +109,7 @@ function Get-Policies
|
|||
$null = (New-ItemProperty -Path $regPath -Name WAU_NotificationLevel -Value 'Full' -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UpdatesAtTime) -and ($($WAUPolicies.WAU_UpdatesAtTime) -ne $($WAUConfig.WAU_UpdatesAtTime)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatesAtTime -Value $($WAUPolicies.WAU_UpdatesAtTime) -Force -Confirm:$false)
|
||||
|
@ -119,7 +119,7 @@ function Get-Policies
|
|||
$folder = $service.GetFolder('\')
|
||||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if (($definition.Triggers.Item($triggerId).Type -eq '2') -or ($definition.Triggers.Item($triggerId).Type -eq '3'))
|
||||
|
@ -143,7 +143,7 @@ function Get-Policies
|
|||
$folder = $service.GetFolder('\')
|
||||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if (($definition.Triggers.Item($triggerId).Type -eq '2') -or ($definition.Triggers.Item($triggerId).Type -eq '3'))
|
||||
|
@ -155,11 +155,11 @@ function Get-Policies
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$null = $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force -Confirm:$false)
|
||||
|
@ -168,7 +168,7 @@ function Get-Policies
|
|||
$folder = $service.GetFolder('\')
|
||||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if (($definition.Triggers.Item($triggerId).Type -eq '2') -or ($definition.Triggers.Item($triggerId).Type -eq '3'))
|
||||
|
@ -178,15 +178,15 @@ function Get-Policies
|
|||
$triggerId -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$null = $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null)
|
||||
|
||||
|
||||
if (!$($WAUConfig.WAU_UpdatesAtTime))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force -Confirm:$false)
|
||||
$Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate')
|
||||
}
|
||||
|
||||
|
||||
if ($($WAUPolicies.WAU_UpdatesInterval) -ne 'Never')
|
||||
{
|
||||
#Count Triggers (correctly)
|
||||
|
@ -246,7 +246,7 @@ function Get-Policies
|
|||
$folder = $service.GetFolder('\')
|
||||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if (($definition.Triggers.Item($triggerId).Type -eq '2') -or ($definition.Triggers.Item($triggerId).Type -eq '3'))
|
||||
|
@ -256,17 +256,17 @@ function Get-Policies
|
|||
$triggerId -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$null = $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null)
|
||||
|
||||
|
||||
if (!$($WAUConfig.WAU_UpdatesAtTime))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force -Confirm:$false)
|
||||
$Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate')
|
||||
}
|
||||
|
||||
|
||||
$tasktrigger = (New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime))
|
||||
|
||||
|
||||
# Count Triggers (correctly)
|
||||
$service = (New-Object -ComObject Schedule.Service)
|
||||
$service.Connect($env:COMPUTERNAME)
|
||||
|
@ -274,7 +274,7 @@ function Get-Policies
|
|||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
$null = $definition.Triggers.Count
|
||||
|
||||
|
||||
if ($definition.Triggers.Count -gt 0)
|
||||
{
|
||||
$triggers = @()
|
||||
|
@ -288,7 +288,7 @@ function Get-Policies
|
|||
}
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUPolicies.WAU_UpdatesAtLogon) -ne $($WAUConfig.WAU_UpdatesAtLogon)))
|
||||
{
|
||||
if ($WAUPolicies.WAU_UpdatesAtLogon -eq 1)
|
||||
|
@ -303,7 +303,7 @@ function Get-Policies
|
|||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
$triggerLogon = $false
|
||||
|
||||
|
||||
foreach ($trigger in $definition.Triggers)
|
||||
{
|
||||
if ($trigger.Type -eq '9')
|
||||
|
@ -327,7 +327,7 @@ function Get-Policies
|
|||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
$null = $definition.Triggers.Count
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if ($definition.Triggers.Item($triggerId).Type -eq '9')
|
||||
|
@ -336,10 +336,10 @@ function Get-Policies
|
|||
$triggerId -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$null = $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null)
|
||||
}
|
||||
|
||||
|
||||
$ChangedSettings++
|
||||
}
|
||||
elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUConfig.WAU_UpdatesAtLogon) -or $($WAUConfig.WAU_UpdatesAtLogon) -eq 0))
|
||||
|
@ -350,7 +350,7 @@ function Get-Policies
|
|||
$folder = $service.GetFolder('\')
|
||||
$task = $folder.GetTask('Winget-AutoUpdate')
|
||||
$definition = $task.Definition
|
||||
|
||||
|
||||
for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++)
|
||||
{
|
||||
if ($definition.Triggers.Item($triggerId).Type -eq '9')
|
||||
|
@ -359,15 +359,15 @@ function Get-Policies
|
|||
$triggerId -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$null = $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_UserContext) -and ($($WAUPolicies.WAU_UserContext) -ne $($WAUConfig.WAU_UserContext)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
||||
|
||||
if ($WAUPolicies.WAU_UserContext -eq 1)
|
||||
{
|
||||
# Settings for the scheduled task in User context
|
||||
|
@ -390,11 +390,11 @@ function Get-Policies
|
|||
$null = (Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$false -ErrorAction SilentlyContinue)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_DesktopShortcut) -and ($($WAUPolicies.WAU_DesktopShortcut) -ne $($WAUConfig.WAU_DesktopShortcut)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_DesktopShortcut -Value $($WAUPolicies.WAU_DesktopShortcut) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
||||
|
||||
if ($WAUPolicies.WAU_DesktopShortcut -eq 1)
|
||||
{
|
||||
Add-Shortcut 'wscript.exe' "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" 'Manual start of Winget-AutoUpdate (WAU)...'
|
||||
|
@ -411,18 +411,18 @@ function Get-Policies
|
|||
$null = (Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_StartMenuShortcut) -and ($($WAUPolicies.WAU_StartMenuShortcut) -ne $($WAUConfig.WAU_StartMenuShortcut)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_StartMenuShortcut -Value $($WAUPolicies.WAU_StartMenuShortcut) -PropertyType DWord -Force -Confirm:$false)
|
||||
|
||||
|
||||
if ($WAUPolicies.WAU_StartMenuShortcut -eq 1)
|
||||
{
|
||||
if (!(Test-Path -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)"))
|
||||
{
|
||||
$null = (New-Item -ItemType Directory -Force -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Confirm:$false)
|
||||
}
|
||||
|
||||
|
||||
Add-Shortcut 'wscript.exe' "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" 'Manual start of Winget-AutoUpdate (WAU)...'
|
||||
Add-Shortcut 'wscript.exe' "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" 'Open existing WAU logs...'
|
||||
Add-Shortcut 'wscript.exe' "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" 'Help for WAU...'
|
||||
|
@ -439,7 +439,7 @@ function Get-Policies
|
|||
$null = (Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_MaxLogFiles) -and ($($WAUPolicies.WAU_MaxLogFiles) -ne $($WAUConfig.WAU_MaxLogFiles)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogFiles -Value $($WAUPolicies.WAU_MaxLogFiles.TrimEnd(' ', '\', '/')) -Force -Confirm:$false)
|
||||
|
@ -450,7 +450,7 @@ function Get-Policies
|
|||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogFiles -Value 3 -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
if ($null -ne $($WAUPolicies.WAU_MaxLogSize) -and ($($WAUPolicies.WAU_MaxLogSize) -ne $($WAUConfig.WAU_MaxLogSize)))
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogSize -Value $($WAUPolicies.WAU_MaxLogSize.TrimEnd(' ', '\', '/')) -Force -Confirm:$false)
|
||||
|
@ -461,11 +461,11 @@ function Get-Policies
|
|||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogSize -Value 1048576 -Force -Confirm:$false)
|
||||
$ChangedSettings++
|
||||
}
|
||||
|
||||
|
||||
# Get WAU Configurations after Policies change
|
||||
$Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $($WAUPolicies.WAU_ActivateGPOManagement), $ChangedSettings
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ function Get-WAUAvailableVersion
|
|||
{
|
||||
# Log
|
||||
Write-ToLog -LogMsg 'WAU AutoUpdate Pre-release versions is Enabled' -LogColor 'Cyan'
|
||||
|
||||
|
||||
# Get latest pre-release info
|
||||
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases'
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ function Get-WAUAvailableVersion
|
|||
# Get latest stable info
|
||||
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
|
||||
}
|
||||
|
||||
|
||||
# Return version
|
||||
return ((Invoke-WebRequest -Uri $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace('v', '')
|
||||
}
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
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')
|
||||
})
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
|
@ -27,27 +27,27 @@ function Get-WingetCmd
|
|||
{
|
||||
#Get Winget Location in User context
|
||||
$WingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
if ($WingetCmd)
|
||||
{
|
||||
$Script:Winget = $WingetCmd.Source
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!($Script:Winget))
|
||||
{
|
||||
Write-ToLog 'Winget not installed or detected !' 'Red'
|
||||
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
return $true
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,60 +8,60 @@ function Get-WingetOutdatedApps
|
|||
[string]$Version
|
||||
[string]$AvailableVersion
|
||||
}
|
||||
|
||||
|
||||
# Get list of available upgrades on winget format
|
||||
$upgradeResult = (& $Winget upgrade --source winget | Out-String)
|
||||
|
||||
|
||||
# Start Convertion of winget format to an array. Check if "-----" exists (Winget Error Handling)
|
||||
if (!($upgradeResult -match '-----'))
|
||||
{
|
||||
return "An unusual thing happened (maybe all apps are upgraded):`n$upgradeResult"
|
||||
}
|
||||
|
||||
|
||||
# Split winget output to lines
|
||||
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object -FilterScript {
|
||||
$_
|
||||
}
|
||||
|
||||
|
||||
# Find the line that starts with "------"
|
||||
$fl = 0
|
||||
while (-not $lines[$fl].StartsWith('-----'))
|
||||
{
|
||||
$fl++
|
||||
}
|
||||
|
||||
|
||||
# Get header line
|
||||
$fl = $fl - 1
|
||||
|
||||
|
||||
# Get header titles [without remove seperator]
|
||||
$index = $lines[$fl] -split '(?<=\s)(?!\s)'
|
||||
|
||||
|
||||
# Line $fl has the header, we can find char where we find ID and Version [and manage non latin characters]
|
||||
$idStart = $($index[0] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
$versionStart = $idStart + $($index[1] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
$availableStart = $versionStart + $($index[2] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
|
||||
|
||||
# Now cycle in real package and split accordingly
|
||||
$upgradeList = @()
|
||||
|
||||
|
||||
for ($i = $fl + 2; $i -lt $lines.Length; $i++)
|
||||
{
|
||||
$line = $lines[$i] -replace '[\u2026]', ' ' #Fix "..." in long names
|
||||
|
||||
|
||||
if ($line.StartsWith('-----'))
|
||||
{
|
||||
# Get header line
|
||||
$fl = $i - 1
|
||||
|
||||
|
||||
# Get header titles [without remove seperator]
|
||||
$index = $lines[$fl] -split '(?<=\s)(?!\s)'
|
||||
|
||||
|
||||
# Line $fl has the header, we can find char where we find ID and Version [and manage non latin characters]
|
||||
$idStart = $($index[0] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
$versionStart = $idStart + $($index[1] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
$availableStart = $versionStart + $($index[2] -replace '[\u4e00-\u9fa5]', '**').Length
|
||||
}
|
||||
|
||||
|
||||
# (Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications
|
||||
if ($line -match '\w\.\w')
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ function Get-WingetOutdatedApps
|
|||
$upgradeList += $software
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# If current user is not system, remove system apps from list
|
||||
if ($IsSystem -eq $false)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ function Get-WingetOutdatedApps
|
|||
$SystemApps -notcontains $_.Id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $upgradeList | Sort-Object -Property {
|
||||
Get-Random
|
||||
}
|
||||
|
|
|
@ -2,16 +2,16 @@ function Get-WingetSystemApps
|
|||
{
|
||||
# Json File, where to export system installed apps
|
||||
$jsonFile = ('{0}\winget_system_apps.txt' -f $WorkingDir)
|
||||
|
||||
|
||||
# Get list of installed Winget apps to json file
|
||||
$null = (& $Winget export -o $jsonFile --accept-source-agreements -s winget)
|
||||
|
||||
|
||||
# Convert json file to txt file with app ids
|
||||
$InstalledApps = (Get-Content -Path $jsonFile | ConvertFrom-Json)
|
||||
|
||||
|
||||
# Save app list
|
||||
$null = (Set-Content -Value $InstalledApps.Sources.Packages.PackageIdentifier -Path $jsonFile -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Sort app list
|
||||
$null = (Get-Content -Path $jsonFile | Sort-Object | Set-Content -Path $jsonFile -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ function Invoke-LogRotation
|
|||
URL: https://www.powershellgallery.com/packages/Communary.Logger/1.1
|
||||
Date: 21.11.2014
|
||||
Version: 1.0
|
||||
#>
|
||||
#>
|
||||
param
|
||||
(
|
||||
[string]
|
||||
|
@ -22,18 +22,18 @@ function Invoke-LogRotation
|
|||
[int]
|
||||
$MaxLogSize
|
||||
)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
# get current size of log file
|
||||
$currentSize = (Get-Item -Path $LogFile).Length
|
||||
|
||||
|
||||
# get log name
|
||||
$logFileName = (Split-Path -Path $LogFile -Leaf)
|
||||
$logFilePath = (Split-Path -Path $LogFile)
|
||||
$logFileNameWithoutExtension = [IO.Path]::GetFileNameWithoutExtension($logFileName)
|
||||
$logFileNameExtension = [IO.Path]::GetExtension($logFileName)
|
||||
|
||||
|
||||
# if MaxLogFiles is 1 just keep the original one and let it grow
|
||||
if (-not ($MaxLogFiles -eq 1))
|
||||
{
|
||||
|
@ -41,10 +41,10 @@ function Invoke-LogRotation
|
|||
{
|
||||
# construct name of archived log file
|
||||
$newLogFileName = $logFileNameWithoutExtension + (Get-Date -Format 'yyyyMMddHHmmss').ToString() + $logFileNameExtension
|
||||
|
||||
|
||||
# copy old log file to new using the archived name constructed above
|
||||
$null = (Copy-Item -Path $LogFile -Destination (Join-Path -Path (Split-Path -Path $LogFile) -ChildPath $newLogFileName))
|
||||
|
||||
|
||||
# Create a new log file
|
||||
try
|
||||
{
|
||||
|
@ -64,16 +64,16 @@ function Invoke-LogRotation
|
|||
{
|
||||
return $False
|
||||
}
|
||||
|
||||
|
||||
# if MaxLogFiles is 0 don't delete any old archived log files
|
||||
if (-not ($MaxLogFiles -eq 0))
|
||||
{
|
||||
# set filter to search for archived log files
|
||||
$archivedLogFileFilter = $logFileNameWithoutExtension + '??????????????' + $logFileNameExtension
|
||||
|
||||
|
||||
# get archived log files
|
||||
$oldLogFiles = (Get-Item -Path "$(Join-Path -Path $logFilePath -ChildPath $archivedLogFileFilter)")
|
||||
|
||||
|
||||
if ([bool]$oldLogFiles)
|
||||
{
|
||||
# compare found log files to MaxLogFiles parameter of the log object, and delete oldest until we are
|
||||
|
@ -85,16 +85,16 @@ function Invoke-LogRotation
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Log Header
|
||||
$Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-Culture).DateTimeFormat.ShortDatePattern)`n##################################################"
|
||||
$null = ($Log | Out-File -FilePath $LogFile -Append -Force)
|
||||
Write-ToLog -LogMsg 'Running in System context'
|
||||
|
||||
|
||||
if ($ActivateGPOManagement)
|
||||
{
|
||||
Write-ToLog -LogMsg 'Activated WAU GPO Management detected, comparing...'
|
||||
|
||||
|
||||
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0)
|
||||
{
|
||||
Write-ToLog -LogMsg 'Changed settings detected and applied' -LogColor 'Yellow'
|
||||
|
@ -104,9 +104,9 @@ function Invoke-LogRotation
|
|||
Write-ToLog -LogMsg 'No Changed settings detected' -LogColor 'Yellow'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Write-ToLog -LogMsg ('Max Log Size reached: {0} bytes - Rotated Logs' -f $MaxLogSize)
|
||||
|
||||
|
||||
return $True
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ function Invoke-ModsProtect
|
|||
[string]
|
||||
$ModsPath
|
||||
)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$directory = (Get-Item -Path $ModsPath -ErrorAction SilentlyContinue)
|
||||
|
@ -22,7 +22,7 @@ function Invoke-ModsProtect
|
|||
$userName = $ntAccount.Value
|
||||
$userRights = [Security.AccessControl.FileSystemRights]'Write'
|
||||
$hasWriteAccess = $False
|
||||
|
||||
|
||||
foreach ($access in $acl.Access)
|
||||
{
|
||||
if ($access.IdentityReference.Value -eq $userName -and $access.FileSystemRights -eq $userRights)
|
||||
|
@ -31,48 +31,48 @@ function Invoke-ModsProtect
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($hasWriteAccess)
|
||||
{
|
||||
# Disable inheritance
|
||||
$acl.SetAccessRuleProtection($True, $True)
|
||||
|
||||
|
||||
# Remove any existing rules
|
||||
$acl.Access | ForEach-Object -Process {
|
||||
$acl.RemoveAccessRule($_)
|
||||
}
|
||||
|
||||
|
||||
# SYSTEM Full - S-1-5-18
|
||||
$userSID = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('S-1-5-18'))
|
||||
$rule = (New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList ($userSID, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow'))
|
||||
$acl.SetAccessRule($rule)
|
||||
# Save the updated ACL
|
||||
$null = (Set-Acl -Path $directory.FullName -AclObject $acl)
|
||||
|
||||
|
||||
# Administrators Full - S-1-5-32-544
|
||||
$acl = (Get-Acl -Path $directory.FullName)
|
||||
$userSID = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('S-1-5-32-544'))
|
||||
$rule = (New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList ($userSID, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow'))
|
||||
$acl.SetAccessRule($rule)
|
||||
$null = (Set-Acl -Path $directory.FullName -AclObject $acl)
|
||||
|
||||
|
||||
# Local Users ReadAndExecute - S-1-5-32-545 S-1-5-11
|
||||
$acl = (Get-Acl -Path $directory.FullName)
|
||||
$userSID = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('S-1-5-32-545'))
|
||||
$rule = (New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList ($userSID, 'ReadAndExecute', 'ContainerInherit,ObjectInherit', 'None', 'Allow'))
|
||||
$acl.SetAccessRule($rule)
|
||||
$null = (Set-Acl -Path $directory.FullName -AclObject $acl)
|
||||
|
||||
|
||||
# Authenticated Users ReadAndExecute - S-1-5-11
|
||||
$acl = (Get-Acl -Path $directory.FullName)
|
||||
$userSID = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList ('S-1-5-11'))
|
||||
$rule = (New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList ($userSID, 'ReadAndExecute', 'ContainerInherit,ObjectInherit', 'None', 'Allow'))
|
||||
$acl.SetAccessRule($rule)
|
||||
$null = (Set-Acl -Path $directory.FullName -AclObject $acl)
|
||||
|
||||
|
||||
return $True
|
||||
}
|
||||
|
||||
|
||||
return $False
|
||||
}
|
||||
catch
|
||||
|
|
|
@ -4,30 +4,30 @@ function Invoke-PostUpdateActions
|
|||
{
|
||||
# log
|
||||
Write-ToLog -LogMsg 'Running Post Update actions:' -LogColor 'yellow'
|
||||
|
||||
|
||||
# Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ErrorAction SilentlyContinue))
|
||||
{
|
||||
Write-ToLog -LogMsg '-> Creating SymLink for log file in Intune Management Extension log folder' -LogColor 'yellow'
|
||||
$null = New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
|
||||
# Check if Intune Management Extension Logs folder and WAU-install.log exists, make symlink
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue) -and (Test-Path -Path ('{0}\logs\install.log' -f $WorkingDir) -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ErrorAction SilentlyContinue))
|
||||
{
|
||||
Write-Host -Object "`nCreating SymLink for log file (WAU-install) in Intune Management Extension log folder" -ForegroundColor Yellow
|
||||
$null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
Write-ToLog -LogMsg '-> Checking prerequisites...' -LogColor 'yellow'
|
||||
|
||||
|
||||
# Check if Visual C++ 2019 or 2022 installed
|
||||
$Visual2019 = 'Microsoft Visual C++ 2015-2019 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 {
|
||||
$_.GetValue('DisplayName') -like $Visual2019 -or $_.GetValue('DisplayName') -like $Visual2022
|
||||
})
|
||||
|
||||
|
||||
# If not installed, install
|
||||
if (!($path))
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ function Invoke-PostUpdateActions
|
|||
{
|
||||
$OSArch = 'x86'
|
||||
}
|
||||
|
||||
|
||||
Write-ToLog -LogMsg ('-> Downloading VC_redist.{0}.exe...' -f $OSArch)
|
||||
$SourceURL = ('https://aka.ms/vs/17/release/VC_redist.{0}.exe' -f $OSArch)
|
||||
$Installer = ('{0}\VC_redist.{1}.exe' -f $WAUConfig.InstallLocation, $OSArch)
|
||||
|
@ -61,13 +61,13 @@ function Invoke-PostUpdateActions
|
|||
{
|
||||
Write-ToLog -LogMsg '-> Prerequisites checked. OK' -LogColor 'green'
|
||||
}
|
||||
|
||||
|
||||
# Check Package Install
|
||||
Write-ToLog -LogMsg '-> Checking if Winget is installed/up to date' -LogColor 'yellow'
|
||||
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object -FilterScript {
|
||||
$_.DisplayName -eq 'Microsoft.DesktopAppInstaller'
|
||||
}
|
||||
|
||||
|
||||
# Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
|
||||
if ([Version]$TestWinGet.Version -ge '2023.808.2243.0')
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ function Invoke-PostUpdateActions
|
|||
$WinGetURL = 'https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
|
||||
$WebClient = New-Object -TypeName System.Net.WebClient
|
||||
$WebClient.DownloadFile($WinGetURL, ('{0}\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle' -f $WAUConfig.InstallLocation))
|
||||
|
||||
|
||||
# Install WinGet MSIXBundle
|
||||
try
|
||||
{
|
||||
|
@ -92,29 +92,29 @@ function Invoke-PostUpdateActions
|
|||
{
|
||||
Write-ToLog -LogMsg '-> Failed to intall Winget MSIXBundle for App Installer...' -LogColor 'red'
|
||||
}
|
||||
|
||||
|
||||
# Remove WinGet MSIXBundle
|
||||
Remove-Item -Path ('{0}\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle' -f $WAUConfig.InstallLocation) -Force -Confirm:$False -ErrorAction Continue
|
||||
}
|
||||
|
||||
|
||||
# Reset Winget Sources
|
||||
$ResolveWingetPath = Resolve-Path -Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object -Property {
|
||||
[version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1')
|
||||
}
|
||||
|
||||
|
||||
if ($ResolveWingetPath)
|
||||
{
|
||||
# If multiple version, pick last one
|
||||
$WingetPath = $ResolveWingetPath[-1].Path
|
||||
& $WingetPath source reset --force
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg '-> Winget sources reseted.' -LogColor 'green'
|
||||
}
|
||||
|
||||
|
||||
# Create WAU Regkey if not present
|
||||
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate'
|
||||
|
||||
|
||||
if (!(Test-Path -Path $regPath -ErrorAction SilentlyContinue))
|
||||
{
|
||||
$null = (New-Item -Path $regPath -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
@ -128,60 +128,60 @@ function Invoke-PostUpdateActions
|
|||
$null = (New-ItemProperty -Path $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WorkingDir\WAU-Uninstall.ps1`"" -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
$null = (New-ItemProperty -Path $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WorkingDir\WAU-Uninstall.ps1`"" -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
#log
|
||||
Write-ToLog -LogMsg ('-> {0} created.' -f $regPath) -LogColor 'green'
|
||||
}
|
||||
|
||||
|
||||
# Fix Notif where WAU_NotificationLevel is not set
|
||||
$regNotif = Get-ItemProperty -Path $regPath -Name WAU_NotificationLevel -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
if (!$regNotif)
|
||||
{
|
||||
New-ItemProperty -Path $regPath -Name WAU_NotificationLevel -Value Full -Force
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg "-> Notification level setting was missing. Fixed with 'Full' option."
|
||||
}
|
||||
|
||||
|
||||
# Set WAU_MaxLogFiles/WAU_MaxLogSize if not set
|
||||
$MaxLogFiles = Get-ItemProperty -Path $regPath -Name WAU_MaxLogFiles -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
if (!$MaxLogFiles)
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogFiles -Value 3 -PropertyType DWord -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg '-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB).'
|
||||
}
|
||||
|
||||
|
||||
# Set WAU_ListPath if not set
|
||||
$ListPath = Get-ItemProperty -Path $regPath -Name WAU_ListPath -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
if (!$ListPath)
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_ListPath -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg '-> ListPath setting was missing. Fixed with empty string.'
|
||||
}
|
||||
|
||||
|
||||
# Set WAU_ModsPath if not set
|
||||
$ModsPath = (Get-ItemProperty -Path $regPath -Name WAU_ModsPath -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
if (!$ModsPath)
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_ModsPath -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg '-> ModsPath setting was missing. Fixed with empty string.'
|
||||
}
|
||||
|
||||
|
||||
# Security check
|
||||
Write-ToLog -LogMsg '-> Checking Mods Directory:' -LogColor 'yellow'
|
||||
$Protected = Invoke-ModsProtect ('{0}\mods' -f $WAUConfig.InstallLocation)
|
||||
|
||||
|
||||
if ($Protected -eq $True)
|
||||
{
|
||||
Write-ToLog -LogMsg '-> The mods directory is now secured!' -LogColor 'green'
|
||||
|
@ -194,56 +194,56 @@ function Invoke-PostUpdateActions
|
|||
{
|
||||
Write-ToLog -LogMsg "-> Error: The mods directory couldn't be verified as secured!" -LogColor 'red'
|
||||
}
|
||||
|
||||
|
||||
# Convert about.xml if exists (old WAU versions) to reg
|
||||
$WAUAboutPath = ('{0}\config\about.xml' -f $WorkingDir)
|
||||
|
||||
|
||||
if (Test-Path -Path $WAUAboutPath -ErrorAction SilentlyContinue)
|
||||
{
|
||||
[xml]$About = Get-Content -Path $WAUAboutPath -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
$null = (New-ItemProperty -Path $regPath -Name DisplayVersion -Value $About.app.version -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Remove file once converted
|
||||
$null = (Remove-Item -Path $WAUAboutPath -Force -Confirm:$False)
|
||||
|
||||
|
||||
#log
|
||||
Write-ToLog -LogMsg ('-> {0} converted.' -f $WAUAboutPath) -LogColor 'green'
|
||||
}
|
||||
|
||||
|
||||
# Convert config.xml if exists (previous WAU versions) to reg
|
||||
$WAUConfigPath = ('{0}\config\config.xml' -f $WorkingDir)
|
||||
|
||||
|
||||
if (Test-Path -Path $WAUConfigPath -ErrorAction SilentlyContinue)
|
||||
{
|
||||
[xml]$Config = (Get-Content -Path $WAUConfigPath -Encoding UTF8 -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
if ($Config.app.WAUautoupdate -eq 'False')
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
if ($Config.app.NotificationLevel)
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_NotificationLevel -Value $Config.app.NotificationLevel -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
if ($Config.app.UseWAUWhiteList -eq 'True')
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
if ($Config.app.WAUprerelease -eq 'True')
|
||||
{
|
||||
$null = (New-ItemProperty -Path $regPath -Name WAU_UpdatePrerelease -Value 1 -PropertyType DWord -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
# Remove file once converted
|
||||
$null = (Remove-Item -Path $WAUConfigPath -Force -Confirm:$False)
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg ('-> {0} converted.' -f $WAUConfigPath) -LogColor 'green'
|
||||
}
|
||||
|
||||
|
||||
# Remove old functions / files
|
||||
$FileNames = @(
|
||||
('{0}\functions\Get-WAUConfig.ps1' -f $WorkingDir),
|
||||
|
@ -252,24 +252,24 @@ function Invoke-PostUpdateActions
|
|||
('{0}\functions\Write-Log.ps1' -f $WorkingDir),
|
||||
('{0}\Version.txt' -f $WorkingDir)
|
||||
)
|
||||
|
||||
|
||||
foreach ($FileName in $FileNames)
|
||||
{
|
||||
if (Test-Path -Path $FileName -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$null = (Remove-Item -Path $FileName -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg ('-> {0} removed.' -f $FileName) -LogColor 'green'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Remove old registry key
|
||||
$RegistryKeys = @(
|
||||
'VersionMajor',
|
||||
'VersionMinor'
|
||||
)
|
||||
|
||||
|
||||
foreach ($RegistryKey in $RegistryKeys)
|
||||
{
|
||||
if (Get-ItemProperty -Path $regPath -Name $RegistryKey -ErrorAction SilentlyContinue)
|
||||
|
@ -277,13 +277,13 @@ function Invoke-PostUpdateActions
|
|||
$null = (Remove-ItemProperty -Path $regPath -Name $RegistryKey -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Reset WAU_UpdatePostActions Value
|
||||
$null = ($WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 0 -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Get updated WAU Config
|
||||
$Script:WAUConfig = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate')
|
||||
|
||||
|
||||
# log
|
||||
Write-ToLog -LogMsg 'Post Update actions finished' -LogColor 'green'
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ function Start-Init
|
|||
{
|
||||
# Config console output encoding
|
||||
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
||||
|
||||
|
||||
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
|
||||
$Script:ProgressPreference = 'SilentlyContinue'
|
||||
$caller = ((Get-ChildItem -Path $MyInvocation.PSCommandPath).Name)
|
||||
|
||||
|
||||
if ($caller -eq 'Winget-Upgrade.ps1')
|
||||
{
|
||||
# Log Header
|
||||
|
@ -21,7 +21,7 @@ function Start-Init
|
|||
{
|
||||
$Script:LogFile = ('{0}\logs\updates.log' -f $WingetUpdatePath)
|
||||
}
|
||||
|
||||
|
||||
if (!(Test-Path -Path $LogFile -ErrorAction SilentlyContinue))
|
||||
{
|
||||
# Create file if doesn't exist
|
||||
|
@ -48,21 +48,21 @@ function Start-Init
|
|||
$NewAcl.SetAccessRule($fileSystemAccessRule)
|
||||
$null = (Set-Acl -Path $LogFile -AclObject $NewAcl)
|
||||
}
|
||||
|
||||
|
||||
# Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log"))
|
||||
{
|
||||
Write-Host -Object "`nCreating SymLink for log file (WAU-updates) in Intune Management Extension log folder" -ForegroundColor Yellow
|
||||
$null = New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
|
||||
# Check if Intune Management Extension Logs folder and WAU-install.log exists, make symlink
|
||||
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue) -and (Test-Path -Path ('{0}\logs\install.log' -f $WorkingDir) -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ErrorAction SilentlyContinue))
|
||||
{
|
||||
Write-Host -Object "`nCreating SymLink for log file (WAU-install) in Intune Management Extension log folder" -ForegroundColor Yellow
|
||||
$null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
if ($caller -eq 'Winget-Upgrade.ps1')
|
||||
{
|
||||
# Log file
|
||||
|
|
|
@ -25,23 +25,23 @@ function Start-NotifTask
|
|||
[Switch]
|
||||
$UserRun = $false
|
||||
)
|
||||
|
||||
|
||||
if (($WAUConfig.WAU_NotificationLevel -eq 'Full') -or ($WAUConfig.WAU_NotificationLevel -eq 'SuccessOnly' -and $MessageType -eq 'Success') -or ($UserRun))
|
||||
{
|
||||
# XML Toast template creation
|
||||
[xml]$ToastTemplate = New-Object -TypeName system.Xml.XmlDocument
|
||||
$ToastTemplate.LoadXml("<?xml version=`"1.0`" encoding=`"utf-8`"?><toast></toast>")
|
||||
|
||||
|
||||
# Creation of visual node
|
||||
$XMLvisual = $ToastTemplate.CreateElement('visual')
|
||||
|
||||
|
||||
# Creation of a binding node
|
||||
$XMLbinding = $ToastTemplate.CreateElement('binding')
|
||||
$null = $XMLvisual.AppendChild($XMLbinding)
|
||||
$XMLbindingAtt1 = ($ToastTemplate.CreateAttribute('template'))
|
||||
$XMLbindingAtt1.Value = 'ToastGeneric'
|
||||
$null = $XMLbinding.Attributes.Append($XMLbindingAtt1)
|
||||
|
||||
|
||||
$XMLimagepath = ('{0}\icons\{1}.png' -f $WorkingDir, $MessageType)
|
||||
if (Test-Path -Path $XMLimagepath -ErrorAction SilentlyContinue)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ function Start-NotifTask
|
|||
$XMLimageAtt2.Value = ('{0}\icons\{1}.png' -f $WorkingDir, $MessageType)
|
||||
$null = $XMLimage.Attributes.Append($XMLimageAtt2)
|
||||
}
|
||||
|
||||
|
||||
if ($Title)
|
||||
{
|
||||
# Creation of a text node
|
||||
|
@ -64,7 +64,7 @@ function Start-NotifTask
|
|||
$null = $XMLtitle.AppendChild($XMLtitleText)
|
||||
$null = $XMLbinding.AppendChild($XMLtitle)
|
||||
}
|
||||
|
||||
|
||||
if ($Message)
|
||||
{
|
||||
# Creation of a text node
|
||||
|
@ -73,17 +73,17 @@ function Start-NotifTask
|
|||
$null = $XMLtext.AppendChild($XMLtextText)
|
||||
$null = $XMLbinding.AppendChild($XMLtext)
|
||||
}
|
||||
|
||||
|
||||
if ($Body)
|
||||
{
|
||||
# Creation of a group node
|
||||
$XMLgroup = $ToastTemplate.CreateElement('group')
|
||||
$null = $XMLbinding.AppendChild($XMLgroup)
|
||||
|
||||
|
||||
# Creation of a subgroup node
|
||||
$XMLsubgroup = $ToastTemplate.CreateElement('subgroup')
|
||||
$null = $XMLgroup.AppendChild($XMLsubgroup)
|
||||
|
||||
|
||||
# Creation of a text node
|
||||
$XMLcontent = $ToastTemplate.CreateElement('text')
|
||||
$XMLcontentText = $ToastTemplate.CreateTextNode($Body)
|
||||
|
@ -96,10 +96,10 @@ function Start-NotifTask
|
|||
$XMLcontentAtt2.Value = 'true'
|
||||
$null = $XMLcontent.Attributes.Append($XMLcontentAtt2)
|
||||
}
|
||||
|
||||
|
||||
# Creation of actions node
|
||||
$XMLactions = $ToastTemplate.CreateElement('actions')
|
||||
|
||||
|
||||
if ($Button1Text)
|
||||
{
|
||||
# Creation of action node
|
||||
|
@ -118,7 +118,7 @@ function Start-NotifTask
|
|||
$null = $XMLaction.Attributes.Append($XMLactionAtt3)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($ButtonDismiss)
|
||||
{
|
||||
# Creation of action node
|
||||
|
@ -134,23 +134,23 @@ function Start-NotifTask
|
|||
$XMLactionAtt3.Value = 'system'
|
||||
$null = $XMLaction.Attributes.Append($XMLactionAtt3)
|
||||
}
|
||||
|
||||
|
||||
# Creation of tag node
|
||||
$XMLtag = $ToastTemplate.CreateElement('tag')
|
||||
$XMLtagText = $ToastTemplate.CreateTextNode($Balise)
|
||||
$null = $XMLtag.AppendChild($XMLtagText)
|
||||
|
||||
|
||||
# Add the visual node to the xml
|
||||
$null = $ToastTemplate.LastChild.AppendChild($XMLvisual)
|
||||
$null = $ToastTemplate.LastChild.AppendChild($XMLactions)
|
||||
$null = $ToastTemplate.LastChild.AppendChild($XMLtag)
|
||||
|
||||
|
||||
if ($OnClickAction)
|
||||
{
|
||||
$null = $ToastTemplate.toast.SetAttribute('activationType', 'Protocol')
|
||||
$null = $ToastTemplate.toast.SetAttribute('launch', $OnClickAction)
|
||||
}
|
||||
|
||||
|
||||
# if not "Interactive" user, run as system
|
||||
if ($IsSystem)
|
||||
{
|
||||
|
@ -160,9 +160,9 @@ function Start-NotifTask
|
|||
{
|
||||
$null = (New-Item -ItemType Directory -Force -Confirm:$false -Path $ToastTemplateLocation)
|
||||
}
|
||||
|
||||
|
||||
$ToastTemplate.Save(('{0}\notif.xml' -f $ToastTemplateLocation))
|
||||
|
||||
|
||||
# Run Notify scheduled task to notify conneted users
|
||||
$null = (Get-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
@ -174,20 +174,20 @@ function Start-NotifTask
|
|||
$null = (Add-Type -AssemblyName Windows.Data)
|
||||
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
||||
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]
|
||||
|
||||
|
||||
# Prepare XML
|
||||
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
|
||||
$ToastXml.LoadXml($ToastTemplate.OuterXml)
|
||||
|
||||
|
||||
# Specify Launcher App ID
|
||||
$LauncherID = 'Windows.SystemToast.Winget.Notification'
|
||||
|
||||
|
||||
# Prepare and Create Toast
|
||||
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
|
||||
$ToastMessage.Tag = $ToastTemplate.toast.tag
|
||||
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
|
||||
}
|
||||
|
||||
|
||||
# Wait for notification to display
|
||||
Start-Sleep -Seconds 3
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
function Test-ListPath
|
||||
{
|
||||
# URL, UNC or Local Path
|
||||
# URL, UNC or Local Path
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
|
@ -13,7 +13,7 @@ function Test-ListPath
|
|||
[string]
|
||||
$WingetUpdatePath
|
||||
)
|
||||
|
||||
|
||||
if ($UseWhiteList)
|
||||
{
|
||||
$ListType = 'included_apps.txt'
|
||||
|
@ -22,28 +22,28 @@ function Test-ListPath
|
|||
{
|
||||
$ListType = 'excluded_apps.txt'
|
||||
}
|
||||
|
||||
|
||||
# Get local and external list paths
|
||||
$LocalList = -join ($WingetUpdatePath, '\', $ListType)
|
||||
$ExternalList = -join ($ListPath, '\', $ListType)
|
||||
|
||||
|
||||
# Check if a list exists
|
||||
if (Test-Path -Path $LocalList -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$dateLocal = (Get-Item -Path $LocalList).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
|
||||
# If path is URL
|
||||
if ($ListPath -like 'http*')
|
||||
{
|
||||
$ExternalList = -join ($ListPath, '/', $ListType)
|
||||
$wc = (New-Object -TypeName System.Net.WebClient)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$null = $wc.OpenRead($ExternalList).Close()
|
||||
$dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString('yyyy-MM-dd HH:mm:ss')
|
||||
|
||||
|
||||
if ($dateExternal -gt $dateLocal)
|
||||
{
|
||||
try
|
||||
|
@ -63,7 +63,7 @@ function Test-ListPath
|
|||
try
|
||||
{
|
||||
$content = $wc.DownloadString(('{0}' -f $ExternalList))
|
||||
|
||||
|
||||
if ($null -ne $content -and $content -match '\w\.\w')
|
||||
{
|
||||
$wc.DownloadFile($ExternalList, $LocalList)
|
||||
|
@ -96,7 +96,7 @@ function Test-ListPath
|
|||
$Script:ReachNoPath = $True
|
||||
return $False
|
||||
}
|
||||
|
||||
|
||||
if ($dateExternal -gt $dateLocal)
|
||||
{
|
||||
try
|
||||
|
@ -115,7 +115,7 @@ function Test-ListPath
|
|||
{
|
||||
$Script:ReachNoPath = $True
|
||||
}
|
||||
|
||||
|
||||
return $False
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,42 +9,42 @@ function Test-Mods
|
|||
[string]
|
||||
$app
|
||||
)
|
||||
|
||||
|
||||
$ModsPreInstall = $null
|
||||
$ModsOverride = $null
|
||||
$ModsUpgrade = $null
|
||||
$ModsInstall = $null
|
||||
$ModsInstalled = $null
|
||||
$Mods = ('{0}\mods' -f $WorkingDir)
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\{1}-*' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
if (Test-Path -Path ('{0}\{1}-preinstall.ps1' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ModsPreInstall = ('{0}\{1}-preinstall.ps1' -f $Mods, $app)
|
||||
}
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\{1}-override.txt' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ModsOverride = Get-Content -Path ('{0}\{1}-override.txt' -f $Mods, $app) -Raw
|
||||
}
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\{1}-install.ps1' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ModsInstall = ('{0}\{1}-install.ps1' -f $Mods, $app)
|
||||
$ModsUpgrade = ('{0}\{1}-install.ps1' -f $Mods, $app)
|
||||
}
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\{1}-upgrade.ps1' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ModsUpgrade = ('{0}\{1}-upgrade.ps1' -f $Mods, $app)
|
||||
}
|
||||
|
||||
|
||||
if (Test-Path -Path ('{0}\{1}-installed.ps1' -f $Mods, $app) -ErrorAction SilentlyContinue)
|
||||
{
|
||||
$ModsInstalled = ('{0}\{1}-installed.ps1' -f $Mods, $app)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ function Test-ModsPath
|
|||
{
|
||||
# URL, UNC or Local Path
|
||||
# Get local and external Mods paths
|
||||
|
||||
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
|
@ -17,11 +17,11 @@ function Test-ModsPath
|
|||
)
|
||||
$LocalMods = -join ($WingetUpdatePath, '\', 'mods')
|
||||
$ExternalMods = $ModsPath
|
||||
|
||||
|
||||
# Get File Names Locally
|
||||
$InternalModsNames = (Get-ChildItem -Path $LocalMods -Name -Recurse -Include *.ps1, *.txt -ErrorAction SilentlyContinue)
|
||||
$InternalBinsNames = (Get-ChildItem -Path $LocalMods"\bins" -Name -Recurse -Include *.exe -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# If path is URL
|
||||
if ($ExternalMods -like 'http*')
|
||||
{
|
||||
|
@ -35,13 +35,13 @@ function Test-ModsPath
|
|||
catch
|
||||
{
|
||||
$Script:ReachNoPath = $True
|
||||
|
||||
|
||||
return $False
|
||||
}
|
||||
|
||||
|
||||
# Check for bins, download if newer. Delete if not external
|
||||
$ExternalBins = ('{0}/bins' -f $ModsPath)
|
||||
|
||||
|
||||
if ($WebResponse -match 'bins/')
|
||||
{
|
||||
$BinResponse = Invoke-WebRequest -Uri $ExternalBins -UseBasicParsing
|
||||
|
@ -51,7 +51,7 @@ function Test-ModsPath
|
|||
$CleanBinLinks = $BinLinks -replace '/.*/', ''
|
||||
# Modify strings to HREF:s
|
||||
$index = 0
|
||||
|
||||
|
||||
foreach ($Bin in $CleanBinLinks)
|
||||
{
|
||||
if ($Bin)
|
||||
|
@ -60,21 +60,21 @@ function Test-ModsPath
|
|||
}
|
||||
$index++
|
||||
}
|
||||
|
||||
|
||||
# Delete Local Bins that don't exist Externally
|
||||
$index = 0
|
||||
$CleanLinks = $BinLinks -replace '/.*/', ''
|
||||
|
||||
|
||||
foreach ($Bin in $InternalBinsNames)
|
||||
{
|
||||
if ($CleanLinks -notcontains $Bin)
|
||||
{
|
||||
$null = (Remove-Item -Path $LocalMods\bins\$Bin -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
|
||||
$index++
|
||||
}
|
||||
|
||||
|
||||
$CleanBinLinks = $BinLinks -replace '/.*/', ''
|
||||
$Bin = ''
|
||||
# Loop through all links
|
||||
|
@ -87,12 +87,12 @@ function Test-ModsPath
|
|||
$dateLocalBin = ''
|
||||
$null = $wc.OpenRead(('{0}/{1}' -f $ExternalBins, $_)).Close()
|
||||
$dateExternalBin = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString('yyyy-MM-dd HH:mm:ss')
|
||||
|
||||
|
||||
if (Test-Path -Path $LocalMods"\bins\"$_)
|
||||
{
|
||||
$dateLocalBin = (Get-Item -Path ('{0}\bins\{1}' -f $LocalMods, $_)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
|
||||
if ($dateExternalBin -gt $dateLocalBin)
|
||||
{
|
||||
$SaveBin = Join-Path -Path ('{0}\bins' -f $LocalMods) -ChildPath $_
|
||||
|
@ -101,14 +101,14 @@ function Test-ModsPath
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Collect the external list of href links
|
||||
$ModLinks = $WebResponse.Links | Select-Object -ExpandProperty HREF
|
||||
# If there's a directory path in the HREF:s, delete it (IIS)
|
||||
$CleanLinks = $ModLinks -replace '/.*/', ''
|
||||
# Modify strings to HREF:s
|
||||
$index = 0
|
||||
|
||||
|
||||
foreach ($Mod in $CleanLinks)
|
||||
{
|
||||
if ($Mod)
|
||||
|
@ -117,12 +117,12 @@ function Test-ModsPath
|
|||
}
|
||||
$index++
|
||||
}
|
||||
|
||||
|
||||
# Delete Local Mods that don't exist Externally
|
||||
$DeletedMods = 0
|
||||
$index = 0
|
||||
$CleanLinks = $ModLinks -replace '/.*/', ''
|
||||
|
||||
|
||||
foreach ($Mod in $InternalModsNames)
|
||||
{
|
||||
if ($CleanLinks -notcontains $Mod)
|
||||
|
@ -132,11 +132,11 @@ function Test-ModsPath
|
|||
}
|
||||
$index++
|
||||
}
|
||||
|
||||
|
||||
$CleanLinks = $ModLinks -replace '/.*/', ''
|
||||
|
||||
|
||||
# Loop through all links
|
||||
|
||||
|
||||
$CleanLinks | ForEach-Object -Process {
|
||||
# Check for .ps1/.txt in listing/HREF:s in an index page pointing to .ps1/.txt
|
||||
if (($_ -like '*.ps1') -or ($_ -like '*.txt'))
|
||||
|
@ -147,12 +147,12 @@ function Test-ModsPath
|
|||
$dateLocalMod = ''
|
||||
$null = $wc.OpenRead(('{0}/{1}' -f $ExternalMods, $_)).Close()
|
||||
$dateExternalMod = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString('yyyy-MM-dd HH:mm:ss')
|
||||
|
||||
|
||||
if (Test-Path -Path $LocalMods"\"$_)
|
||||
{
|
||||
$dateLocalMod = (Get-Item -Path ('{0}\{1}' -f $LocalMods, $_)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
|
||||
if ($dateExternalMod -gt $dateLocalMod)
|
||||
{
|
||||
try
|
||||
|
@ -185,34 +185,34 @@ function Test-ModsPath
|
|||
Write-ToLog -LogMsg 'Azure Blob Storage set as mod source'
|
||||
Write-ToLog -LogMsg 'Checking AZCopy'
|
||||
Get-AZCopy $WingetUpdatePath
|
||||
|
||||
|
||||
# Safety check to make sure we really do have azcopy.exe and a Blob URL
|
||||
if ((Test-Path -Path ('{0}\azcopy.exe' -f $WingetUpdatePath) -PathType Leaf) -and ($null -ne $AzureBlobSASURL))
|
||||
{
|
||||
Write-ToLog -LogMsg 'Syncing Blob storage with local storage'
|
||||
|
||||
|
||||
$AZCopySyncOutput = & $WingetUpdatePath\azcopy.exe sync $AzureBlobSASURL $LocalMods --from-to BlobLocal --delete-destination=true
|
||||
$AZCopyOutputLines = $AZCopySyncOutput.Split([Environment]::NewLine)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
if ($AZCopyAdditions -ne 0)
|
||||
{
|
||||
$ModsUpdated = $AZCopyAdditions
|
||||
}
|
||||
|
||||
|
||||
if ($AZCopyDeletions -ne 0)
|
||||
{
|
||||
$DeletedMods = $AZCopyDeletions
|
||||
}
|
||||
|
||||
|
||||
if ($AZCopySyncErrorRegex.Match($_).Value)
|
||||
{
|
||||
Write-ToLog -LogMsg ('AZCopy Sync Error! {0}' -f $_)
|
||||
|
@ -223,18 +223,18 @@ function Test-ModsPath
|
|||
{
|
||||
Write-ToLog -LogMsg "Error 'azcopy.exe' or SAS Token not found!"
|
||||
}
|
||||
|
||||
|
||||
return $ModsUpdated, $DeletedMods
|
||||
}
|
||||
else
|
||||
{
|
||||
# If path is UNC or local
|
||||
$ExternalBins = ('{0}\bins' -f $ModsPath)
|
||||
|
||||
|
||||
if (Test-Path -Path $ExternalBins"\*.exe")
|
||||
{
|
||||
$ExternalBinsNames = (Get-ChildItem -Path $ExternalBins -Name -Recurse -Include *.exe)
|
||||
|
||||
|
||||
# Delete Local Bins that don't exist Externally
|
||||
foreach ($Bin in $InternalBinsNames)
|
||||
{
|
||||
|
@ -243,35 +243,35 @@ function Test-ModsPath
|
|||
$null = (Remove-Item -Path $LocalMods\bins\$Bin -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Copy newer external bins
|
||||
foreach ($Bin in $ExternalBinsNames)
|
||||
{
|
||||
$dateExternalBin = ''
|
||||
$dateLocalBin = ''
|
||||
|
||||
|
||||
if (Test-Path -Path $LocalMods"\bins\"$Bin)
|
||||
{
|
||||
$dateLocalBin = (Get-Item -Path ('{0}\bins\{1}' -f $LocalMods, $Bin)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
|
||||
$dateExternalBin = (Get-Item -Path ('{0}\{1}' -f $ExternalBins, $Bin)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
|
||||
|
||||
if ($dateExternalBin -gt $dateLocalBin)
|
||||
{
|
||||
$null = Copy-Item -Path $ExternalBins\$Bin -Destination $LocalMods\bins\$Bin -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((Test-Path -Path $ExternalMods"\*.ps1") -or (Test-Path -Path $ExternalMods"\*.txt"))
|
||||
{
|
||||
# Get File Names Externally
|
||||
$ExternalModsNames = Get-ChildItem -Path $ExternalMods -Name -Recurse -Include *.ps1, *.txt
|
||||
|
||||
|
||||
# Delete Local Mods that don't exist Externally
|
||||
$DeletedMods = 0
|
||||
|
||||
|
||||
foreach ($Mod in $InternalModsNames)
|
||||
{
|
||||
if ($Mod -notin $ExternalModsNames)
|
||||
|
@ -280,7 +280,7 @@ function Test-ModsPath
|
|||
$DeletedMods++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Copy newer external mods
|
||||
foreach ($Mod in $ExternalModsNames)
|
||||
{
|
||||
|
@ -290,9 +290,9 @@ function Test-ModsPath
|
|||
{
|
||||
$dateLocalMod = (Get-Item -Path ('{0}\{1}' -f $LocalMods, $Mod)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
}
|
||||
|
||||
|
||||
$dateExternalMod = (Get-Item -Path ('{0}\{1}' -f $ExternalMods, $Mod)).LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
|
||||
|
||||
|
||||
if ($dateExternalMod -gt $dateLocalMod)
|
||||
{
|
||||
$null = Copy-Item -Path $ExternalMods\$Mod -Destination $LocalMods\$Mod -Force -ErrorAction SilentlyContinue
|
||||
|
@ -304,7 +304,7 @@ function Test-ModsPath
|
|||
{
|
||||
$Script:ReachNoPath = $True
|
||||
}
|
||||
|
||||
|
||||
return $ModsUpdated, $DeletedMods
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
function Test-Network
|
||||
{
|
||||
#Init
|
||||
|
||||
|
||||
$timeout = 0
|
||||
|
||||
|
||||
# Test connectivity during 30 min then timeout
|
||||
Write-ToLog -LogMsg 'Checking internet connection...' -LogColor 'Yellow'
|
||||
while ($timeout -lt 1800)
|
||||
{
|
||||
$URLtoTest = 'https://raw.githubusercontent.com/Romanitho/Winget-AutoUpdate/main/LICENSE'
|
||||
$URLcontent = ((Invoke-WebRequest -Uri $URLtoTest -UseBasicParsing).content)
|
||||
|
||||
|
||||
if ($URLcontent -like '*MIT License*')
|
||||
{
|
||||
Write-ToLog -LogMsg 'Connected !' -LogColor 'Green'
|
||||
|
||||
|
||||
# Check for metered connection
|
||||
$null = (Add-Type -AssemblyName Windows.Networking)
|
||||
$null = [Windows.Networking.Connectivity.NetworkInformation, Windows, ContentType = WindowsRuntime]
|
||||
$cost = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile().GetConnectionCost()
|
||||
|
||||
|
||||
if ($cost.ApproachingDataLimit -or $cost.OverDataLimit -or $cost.Roaming -or $cost.BackgroundDataUsageRestricted -or ($cost.NetworkCostType -ne 'Unrestricted'))
|
||||
{
|
||||
Write-ToLog -LogMsg 'Metered connection detected.' -LogColor 'Yellow'
|
||||
|
||||
|
||||
if ($WAUConfig.WAU_DoNotRunOnMetered -eq 1)
|
||||
{
|
||||
Write-ToLog -LogMsg 'WAU is configured to bypass update checking on metered connection'
|
||||
|
@ -46,13 +46,13 @@ function Test-Network
|
|||
{
|
||||
Start-Sleep -Seconds 10
|
||||
$timeout += 10
|
||||
|
||||
|
||||
# Send Warning Notif if no connection for 5 min
|
||||
if ($timeout -eq 300)
|
||||
{
|
||||
# Log
|
||||
Write-ToLog -LogMsg "Notify 'No connection' sent." -LogColor 'Yellow'
|
||||
|
||||
|
||||
# Notif
|
||||
$Title = $NotifLocale.local.outputs.output[0].title
|
||||
$Message = $NotifLocale.local.outputs.output[0].message
|
||||
|
@ -62,16 +62,16 @@ function Test-Network
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Send Timeout Notif if no connection for 30 min
|
||||
Write-ToLog -LogMsg 'Timeout. No internet connection !' -LogColor 'Red'
|
||||
|
||||
|
||||
# Notif
|
||||
$Title = $NotifLocale.local.outputs.output[1].title
|
||||
$Message = $NotifLocale.local.outputs.output[1].message
|
||||
$MessageType = 'error'
|
||||
$Balise = 'Connection'
|
||||
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise
|
||||
|
||||
|
||||
return $false
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ function Test-PendingReboot
|
|||
{
|
||||
$Computer = $env:COMPUTERNAME
|
||||
$PendingReboot = $false
|
||||
|
||||
|
||||
$HKLM = [UInt32] '0x80000002'
|
||||
$WMI_Reg = [WMIClass] ('\\{0}\root\default:StdRegProv' -f $Computer)
|
||||
|
||||
|
||||
if ($WMI_Reg)
|
||||
{
|
||||
if (($WMI_Reg.EnumKey($HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\')).sNames -contains 'RebootPending')
|
||||
|
@ -18,7 +18,7 @@ function Test-PendingReboot
|
|||
{
|
||||
$PendingReboot = $true
|
||||
}
|
||||
|
||||
|
||||
# Checking for SCCM namespace
|
||||
$SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
|
||||
if ($SCCM_Namespace)
|
||||
|
@ -29,6 +29,6 @@ function Test-PendingReboot
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $PendingReboot
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ function Update-App
|
|||
{
|
||||
$Button1Text = $NotifLocale.local.outputs.output[10].message
|
||||
}
|
||||
|
||||
|
||||
# Send available update notification
|
||||
Write-ToLog -LogMsg ('Updating {0} from {1} to {2}...' -f $app.Name, $app.Version, $app.AvailableVersion) -LogColor 'Cyan'
|
||||
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
|
||||
|
@ -21,20 +21,20 @@ function Update-App
|
|||
$MessageType = 'info'
|
||||
$Balise = $($app.Name)
|
||||
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text
|
||||
|
||||
|
||||
# Check if mods exist for preinstall/install/upgrade
|
||||
$ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id)
|
||||
|
||||
|
||||
# Winget upgrade
|
||||
Write-ToLog -LogMsg ("########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '{0}' ##########" -f $app.Id) -LogColor 'Gray'
|
||||
|
||||
|
||||
# If PreInstall script exist
|
||||
if ($ModsPreInstall)
|
||||
{
|
||||
Write-ToLog -LogMsg ('Modifications for {0} before upgrade are being applied...' -f $app.Id) -LogColor 'Yellow'
|
||||
& "$ModsPreInstall"
|
||||
}
|
||||
|
||||
|
||||
# Run Winget Upgrade command
|
||||
if ($ModsOverride)
|
||||
{
|
||||
|
@ -46,17 +46,17 @@ function Update-App
|
|||
Write-ToLog -LogMsg ('-> Running: Winget upgrade --id {0} --accept-package-agreements --accept-source-agreements -h' -f $app.Id)
|
||||
& $Winget upgrade --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -FilePath $LogFile -Append
|
||||
}
|
||||
|
||||
|
||||
if ($ModsUpgrade)
|
||||
{
|
||||
Write-ToLog -LogMsg ('Modifications for {0} during upgrade are being applied...' -f $app.Id) -LogColor 'Yellow'
|
||||
& "$ModsUpgrade"
|
||||
}
|
||||
|
||||
|
||||
# Check if application updated properly
|
||||
$FailedToUpgrade = $false
|
||||
$ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion)
|
||||
|
||||
|
||||
if ($ConfirmInstall -ne $true)
|
||||
{
|
||||
# Upgrade failed!
|
||||
|
@ -68,10 +68,10 @@ function Update-App
|
|||
$FailedToUpgrade = $true
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
# If app failed to upgrade, run Install command
|
||||
Write-ToLog -LogMsg ('-> An upgrade for {0} failed, now trying an install instead...' -f $app.Name) -LogColor 'Yellow'
|
||||
|
||||
|
||||
if ($ModsOverride)
|
||||
{
|
||||
Write-ToLog -LogMsg ('-> Running (overriding default): Winget install --id {0} --accept-package-agreements --accept-source-agreements --force --override {1}' -f $app.Id, $ModsOverride)
|
||||
|
@ -82,13 +82,13 @@ function Update-App
|
|||
Write-ToLog -LogMsg ('-> Running: Winget install --id {0} --accept-package-agreements --accept-source-agreements --force -h' -f $app.Id)
|
||||
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements --force -h | Tee-Object -FilePath $LogFile -Append
|
||||
}
|
||||
|
||||
|
||||
if ($ModsInstall)
|
||||
{
|
||||
Write-ToLog -LogMsg ('Modifications for {0} during install are being applied...' -f $app.Id) -LogColor 'Yellow'
|
||||
& "$ModsInstall"
|
||||
}
|
||||
|
||||
|
||||
# Check if application installed properly
|
||||
$ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion)
|
||||
if ($ConfirmInstall -eq $false)
|
||||
|
@ -96,7 +96,7 @@ function Update-App
|
|||
$FailedToUpgrade = $true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($FailedToUpgrade -eq $false)
|
||||
{
|
||||
if ($ModsInstalled)
|
||||
|
@ -105,15 +105,15 @@ function Update-App
|
|||
& "$ModsInstalled"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Write-ToLog -LogMsg ("########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '{0}' ##########" -f $app.Id) -LogColor 'Gray'
|
||||
|
||||
|
||||
# Notify installation
|
||||
if ($FailedToUpgrade -eq $false)
|
||||
{
|
||||
# Send success updated app notification
|
||||
Write-ToLog -LogMsg ('{0} updated to {1} !' -f $app.Name, $app.AvailableVersion) -LogColor 'Green'
|
||||
|
||||
|
||||
# Send Notif
|
||||
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
|
||||
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
|
||||
|
@ -126,7 +126,7 @@ function Update-App
|
|||
{
|
||||
# Send failed updated app notification
|
||||
Write-ToLog -LogMsg ('{0} update failed.' -f $app.Name) -LogColor 'Red'
|
||||
|
||||
|
||||
# Send Notif
|
||||
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
|
||||
$Message = $NotifLocale.local.outputs.output[4].message
|
||||
|
|
|
@ -4,30 +4,30 @@ function Update-WAU
|
|||
{
|
||||
$OnClickAction = 'https://github.com/Romanitho/Winget-AutoUpdate/releases'
|
||||
$Button1Text = $NotifLocale.local.outputs.output[10].message
|
||||
|
||||
|
||||
#Send available update notification
|
||||
$Title = $NotifLocale.local.outputs.output[2].title -f 'Winget-AutoUpdate'
|
||||
$Message = $NotifLocale.local.outputs.output[2].message -f $WAUCurrentVersion, $WAUAvailableVersion
|
||||
$MessageType = 'info'
|
||||
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
||||
|
||||
|
||||
# Run WAU update
|
||||
try
|
||||
{
|
||||
# Force to create a zip file
|
||||
$ZipFile = ('{0}\WAU_update.zip' -f $WorkingDir)
|
||||
$null = New-Item -Path $ZipFile -ItemType File -Force
|
||||
|
||||
|
||||
# Download the zip
|
||||
Write-ToLog -LogMsg ('Downloading the GitHub Repository version {0}' -f $WAUAvailableVersion) -LogColor 'Cyan'
|
||||
$null = (Invoke-RestMethod -Uri ('https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v{0}/WAU.zip' -f ($WAUAvailableVersion)) -OutFile $ZipFile)
|
||||
|
||||
|
||||
# Extract Zip File
|
||||
Write-ToLog -LogMsg 'Unzipping the WAU Update package' -LogColor 'Cyan'
|
||||
$location = ('{0}\WAU_update' -f $WorkingDir)
|
||||
$null = (Expand-Archive -Path $ZipFile -DestinationPath $location -Force)
|
||||
$null = (Get-ChildItem -Path $location -Recurse | Unblock-File -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Update scritps
|
||||
Write-ToLog -LogMsg 'Updating WAU...' -LogColor 'Yellow'
|
||||
$TempPath = (Resolve-Path -Path ('{0}\Winget-AutoUpdate\' -f $location) -ErrorAction SilentlyContinue)[0].Path
|
||||
|
@ -35,31 +35,31 @@ function Update-WAU
|
|||
{
|
||||
$null = (Copy-Item -Path ('{0}\*' -f $TempPath) -Destination ('{0}\' -f $WorkingDir) -Exclude 'icons' -Recurse -Force -Confirm:$false)
|
||||
}
|
||||
|
||||
|
||||
# Remove update zip file and update temp folder
|
||||
Write-ToLog -LogMsg 'Done. Cleaning temp files...' -LogColor 'Cyan'
|
||||
$null = (Remove-Item -Path $ZipFile -Force -Confirm:$false -ErrorAction SilentlyContinue)
|
||||
$null = (Remove-Item -Path $location -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue)
|
||||
|
||||
|
||||
# Set new version to registry
|
||||
$WAUConfig | New-ItemProperty -Name DisplayVersion -Value $WAUAvailableVersion -Force
|
||||
$WAUConfig | New-ItemProperty -Name VersionMajor -Value ([version]$WAUAvailableVersion.Replace('-', '.')).Major -Force
|
||||
$WAUConfig | New-ItemProperty -Name VersionMinor -Value ([version]$WAUAvailableVersion.Replace('-', '.')).Minor -Force
|
||||
|
||||
|
||||
# Set Post Update actions to 1
|
||||
$WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 1 -Force
|
||||
|
||||
|
||||
# Send success Notif
|
||||
Write-ToLog -LogMsg 'WAU Update completed.' -LogColor '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-ToLog -LogMsg 'Re-run WAU'
|
||||
Start-Process -FilePath powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`""
|
||||
|
||||
|
||||
exit
|
||||
}
|
||||
catch
|
||||
|
|
|
@ -11,12 +11,12 @@ function Write-ToLog
|
|||
[string]
|
||||
$LogColor = 'White'
|
||||
)
|
||||
|
||||
|
||||
$Log = ('{0} - {1}' -f (Get-Date -UFormat '%T'), $LogMsg)
|
||||
|
||||
|
||||
#Echo log
|
||||
$Log | Write-Host -ForegroundColor $LogColor
|
||||
|
||||
|
||||
#Write log to file
|
||||
$Log | Out-File -FilePath $LogFile -Append -Force -Confirm:$false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue