Merge pull request #431 from Romanitho/dev

Log Review
pull/432/head
Romain 2023-10-17 22:47:27 +02:00 committed by GitHub
commit 778a751281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 149 deletions

View File

@ -119,16 +119,16 @@ param(
<# FUNCTIONS #> <# FUNCTIONS #>
#Include external Functions #Include external Functions
. "$PSScriptRoot\Winget-AutoUpdate\functions\Start-Init.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Invoke-ModsProtect.ps1" . "$PSScriptRoot\Winget-AutoUpdate\functions\Invoke-ModsProtect.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Get-WinGetAvailableVersion.ps1" . "$PSScriptRoot\Winget-AutoUpdate\functions\Get-WinGetAvailableVersion.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Update-WinGet.ps1" . "$PSScriptRoot\Winget-AutoUpdate\functions\Update-WinGet.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Update-StoreApps.ps1" . "$PSScriptRoot\Winget-AutoUpdate\functions\Update-StoreApps.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Add-Shortcut.ps1" . "$PSScriptRoot\Winget-AutoUpdate\functions\Add-Shortcut.ps1"
. "$PSScriptRoot\Winget-AutoUpdate\functions\Write-ToLog.ps1"
function Install-Prerequisites { function Install-Prerequisites {
Write-Host "`nChecking prerequisites..." -ForegroundColor Yellow Write-ToLog "Checking prerequisites..." "Yellow"
#Check if Visual C++ 2019 or 2022 installed #Check if Visual C++ 2019 or 2022 installed
$Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*" $Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*"
@ -163,33 +163,33 @@ function Install-Prerequisites {
else { else {
$OSArch = "x86" $OSArch = "x86"
} }
Write-host "-> Downloading VC_redist.$OSArch.exe..." Write-ToLog "-> Downloading VC_redist.$OSArch.exe..."
$SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe" $SourceURL = "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
$Installer = $WingetUpdatePath + "\VC_redist.$OSArch.exe" $Installer = $WingetUpdatePath + "\VC_redist.$OSArch.exe"
$ProgressPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force) Invoke-WebRequest $SourceURL -UseBasicParsing -OutFile (New-Item -Path $Installer -Force)
Write-host "-> Installing VC_redist.$OSArch.exe..." Write-ToLog "-> Installing VC_redist.$OSArch.exe..."
Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait Start-Process -FilePath $Installer -Args "/quiet /norestart" -Wait
Remove-Item $Installer -ErrorAction Ignore Remove-Item $Installer -ErrorAction Ignore
Write-host "-> MS Visual C++ 2015-2022 installed successfully" -ForegroundColor Green Write-ToLog "-> MS Visual C++ 2015-2022 installed successfully`n" "Green"
} }
catch { catch {
Write-host "-> MS Visual C++ 2015-2022 installation failed." -ForegroundColor Red Write-ToLog "-> MS Visual C++ 2015-2022 installation failed.`n" "Red"
Start-Sleep 3 Start-Sleep 3
} }
} }
else { else {
Write-host "-> MS Visual C++ 2015-2022 will not be installed." -ForegroundColor Magenta Write-ToLog "-> MS Visual C++ 2015-2022 will not be installed.`n" "Magenta"
} }
} }
else { else {
Write-Host "-> Prerequisites checked. OK" -ForegroundColor Green Write-ToLog "-> Prerequisites checked. OK`n" "Green"
} }
} }
function Install-WinGet { function Install-WinGet {
Write-Host "`nChecking if WinGet is installed/up to date" -ForegroundColor Yellow Write-ToLog "Checking if WinGet is installed/up to date" "Yellow"
#Check available WinGet version, if fail set version to the latest version as of 2023-10-08 #Check available WinGet version, if fail set version to the latest version as of 2023-10-08
$WinGetAvailableVersion = Get-WinGetAvailableVersion $WinGetAvailableVersion = Get-WinGetAvailableVersion
@ -212,7 +212,7 @@ function Install-WinGet {
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) { if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
Write-Host "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" -ForegroundColor Red Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "Red"
#Check if $WingetUpdatePath exist #Check if $WingetUpdatePath exist
if (!(Test-Path $WingetUpdatePath)) { if (!(Test-Path $WingetUpdatePath)) {
@ -221,35 +221,35 @@ function Install-WinGet {
#Downloading and Installing Dependencies in SYSTEM context #Downloading and Installing Dependencies in SYSTEM context
if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) { if (!(Get-AppxPackage -Name 'Microsoft.UI.Xaml.2.7')) {
Write-Host "-> Downloading Microsoft.UI.Xaml.2.7..." Write-ToLog "-> Downloading Microsoft.UI.Xaml.2.7..."
$UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0" $UiXamlUrl = "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0"
$UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip" $UiXamlZip = "$WingetUpdatePath\Microsoft.UI.XAML.2.7.zip"
Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip Invoke-RestMethod -Uri $UiXamlUrl -OutFile $UiXamlZip
Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force Expand-Archive -Path $UiXamlZip -DestinationPath "$WingetUpdatePath\extracted" -Force
try { try {
Write-Host "-> Installing Microsoft.UI.Xaml.2.7..." Write-ToLog "-> Installing Microsoft.UI.Xaml.2.7..."
Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\extracted\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx" -SkipLicense | Out-Null
Write-host "-> Microsoft.UI.Xaml.2.7 installed successfully" -ForegroundColor Green Write-ToLog "-> Microsoft.UI.Xaml.2.7 installed successfully" "Green"
} }
catch { catch {
Write-Host "-> Failed to intall Wicrosoft.UI.Xaml.2.7..." -ForegroundColor Red Write-ToLog "-> Failed to intall Wicrosoft.UI.Xaml.2.7..." "Red"
} }
Remove-Item -Path $UiXamlZip -Force Remove-Item -Path $UiXamlZip -Force
Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse Remove-Item -Path "$WingetUpdatePath\extracted" -Force -Recurse
} }
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) { if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop')) {
Write-Host "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..." Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..."
$VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
$VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx" $VCLibsFile = "$WingetUpdatePath\Microsoft.VCLibs.x64.14.00.Desktop.appx"
Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile
try { try {
Write-Host "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..." Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null
Write-host "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully" -ForegroundColor Green Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully." "Green"
} }
catch { catch {
Write-Host "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." -ForegroundColor Red Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red"
} }
Remove-Item -Path $VCLibsFile -Force Remove-Item -Path $VCLibsFile -Force
} }
@ -258,17 +258,17 @@ function Install-WinGet {
} }
elseif ($WinGetAvailableVersion -match "-pre") { elseif ($WinGetAvailableVersion -match "-pre") {
Write-Host "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" -ForegroundColor Yellow Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release." "Yellow"
Update-StoreApps Update-StoreApps
} }
else { else {
Write-Host "-> WinGet is up to date: v$WinGetInstalledVersion" -ForegroundColor Green Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion`n" "Green"
} }
} }
function Install-WingetAutoUpdate { function Install-WingetAutoUpdate {
Write-Host "`nInstalling WAU..." -ForegroundColor Yellow Write-ToLog "Installing WAU..." "Yellow"
try { try {
#Copy files to location (and clean old install) #Copy files to location (and clean old install)
@ -451,21 +451,17 @@ function Install-WingetAutoUpdate {
New-ItemProperty $regPath -Name WAU_StartMenuShortcut -Value 1 -PropertyType DWord -Force | Out-Null New-ItemProperty $regPath -Name WAU_StartMenuShortcut -Value 1 -PropertyType DWord -Force | Out-Null
} }
#Log file and symlink initialization
Start-Init
#Security check #Security check
Write-host "`nChecking Mods Directory:" -ForegroundColor Yellow Write-ToLog "Checking Mods Directory:" "Yellow"
$Protected = Invoke-ModsProtect "$WingetUpdatePath\mods" $Protected = Invoke-ModsProtect "$WingetUpdatePath\mods"
if ($Protected -eq $True) { if ($Protected -eq $True) {
Write-Host "The mods directory is now secured!`n" -ForegroundColor Green Write-ToLog "-> The mods directory is now secured!`n" "Green"
} }
elseif ($Protected -eq $False) { elseif ($Protected -eq $False) {
Write-Host "The mods directory was already secured!`n" -ForegroundColor Green Write-ToLog "-> The mods directory was already secured!`n" "Green"
} }
else { else {
Write-Host "Error: The mods directory couldn't be verified as secured!`n" -ForegroundColor Red Write-ToLog "-> Error: The mods directory couldn't be verified as secured!`n" "Red"
} }
#Create Shortcuts #Create Shortcuts
@ -482,14 +478,14 @@ function Install-WingetAutoUpdate {
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)..." 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 "WAU Installation succeeded!" -ForegroundColor Green Write-ToLog "WAU Installation succeeded!" "Green"
Start-sleep 1 Start-sleep 1
#Run Winget ? #Run Winget ?
Start-WingetAutoUpdate Start-WingetAutoUpdate
} }
catch { catch {
Write-host "WAU Installation failed! Error $_ - Try running me with admin rights" -ForegroundColor Red Write-ToLog "WAU Installation failed! Error $_ - Try running me with admin rights" "Red"
Start-sleep 1 Start-sleep 1
return $False return $False
} }
@ -497,7 +493,7 @@ function Install-WingetAutoUpdate {
function Uninstall-WingetAutoUpdate { function Uninstall-WingetAutoUpdate {
Write-Host "`nUninstalling WAU..." -ForegroundColor Yellow Write-ToLog "Uninstalling WAU..." "Yellow"
try { try {
#Get registry install location #Get registry install location
@ -534,15 +530,15 @@ function Uninstall-WingetAutoUpdate {
Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null
} }
Write-host "Uninstallation succeeded!" -ForegroundColor Green Write-ToLog "Uninstallation succeeded!`n" "Green"
Start-sleep 1 Start-sleep 1
} }
else { else {
Write-host "$InstallLocation not found! Uninstallation failed!" -ForegroundColor Red Write-ToLog "$InstallLocation not found! Uninstallation failed!`n" "Red"
} }
} }
catch { catch {
Write-host "Uninstallation failed! Run as admin ?" -ForegroundColor Red Write-ToLog "Uninstallation failed! Run as admin ?`n" "Red"
Start-sleep 1 Start-sleep 1
} }
} }
@ -569,19 +565,19 @@ function Start-WingetAutoUpdate {
} }
if ($RunWinget -eq 1) { if ($RunWinget -eq 1) {
try { try {
Write-host "`nRunning Winget-AutoUpdate..." -ForegroundColor Yellow Write-ToLog "Running Winget-AutoUpdate..." "Yellow"
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') { while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') {
Start-Sleep 1 Start-Sleep 1
} }
} }
catch { catch {
Write-host "Failed to run Winget-AutoUpdate..." -ForegroundColor Red Write-ToLog "Failed to run Winget-AutoUpdate..." "Red"
} }
} }
} }
else { else {
Write-host "Skip running Winget-AutoUpdate" Write-ToLog "Skip running Winget-AutoUpdate"
} }
} }
@ -601,6 +597,16 @@ if ("$env:PROCESSOR_ARCHITEW6432" -ne "ARM64") {
} }
} }
#Config console output encoding
$null = cmd /c '' #Tip for ISE
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
$Script:ProgressPreference = 'SilentlyContinue'
#Set install log file
$Script:LogFile = "$WingetUpdatePath\logs\WAU-Installer.log"
Write-Host "`n" Write-Host "`n"
Write-Host "`t 888 888 d8888 888 888" -ForegroundColor Magenta Write-Host "`t 888 888 d8888 888 888" -ForegroundColor Magenta
Write-Host "`t 888 o 888 d88888 888 888" -ForegroundColor Magenta Write-Host "`t 888 o 888 d88888 888 888" -ForegroundColor Magenta
@ -615,18 +621,19 @@ Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -Foreground
Write-Host "`t________________________________________________________`n`n" Write-Host "`t________________________________________________________`n`n"
if (!$Uninstall) { if (!$Uninstall) {
Write-host "Installing WAU to $WingetUpdatePath\" Write-ToLog "Installing WAU to $WingetUpdatePath\"
Install-Prerequisites Install-Prerequisites
Install-WinGet Install-WinGet
Install-WingetAutoUpdate Install-WingetAutoUpdate
} }
else { else {
Write-Host "Uninstalling WAU..." Write-ToLog "Uninstalling WAU..."
Uninstall-WingetAutoUpdate Uninstall-WingetAutoUpdate
} }
if (Test-Path "$WingetUpdatePath\Version.txt") { if (Test-Path "$WingetUpdatePath\Version.txt") {
Remove-Item "$WingetUpdatePath\Version.txt" -Force Remove-Item "$WingetUpdatePath\Version.txt" -Force
} }
Write-host "`nEnd of process." -ForegroundColor Cyan
Write-ToLog "End of process." "Cyan"
Start-Sleep 3 Start-Sleep 3

View File

@ -8,14 +8,19 @@ Get-ChildItem "$WorkingDir\functions" | ForEach-Object { . $_.FullName }
<# MAIN #> <# MAIN #>
#Config console output encoding
$null = cmd /c ''
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
#Check if running account is system or interactive logon #Check if running account is system or interactive logon
$Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem
#Run log initialisation function #Log initialisation
Start-Init $LogFile = "$WorkingDir\logs\updates.log"
Write-ToLog -LogMsg "CHECK FOR APP UPDATES" -IsHeader
#Get settings and Domain/Local Policies (GPO) if activated. #Get settings and Domain/Local Policies (GPO) if activated.
$WAUConfig = Get-WAUConfig $Script:WAUConfig = Get-WAUConfig
if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) { if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
Write-ToLog "WAU Policies management Enabled." Write-ToLog "WAU Policies management Enabled."
} }
@ -343,6 +348,13 @@ if (Test-Network) {
} }
} }
#Adds SymLink if Intune managed
$IntuneLogPath = "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs"
if ((Test-Path "$IntuneLogPath") -and !(Test-Path "$IntuneLogPath\WAU-updates.log")) {
Write-ToLog "`nCreating SymLink for log file (WAU-updates) in Intune Management Extension log folder" "Yellow"
New-Item -Path "$IntuneLogPath\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null
}
#End #End
Write-ToLog "End of process!" "Cyan" Write-ToLog "End of process!" "Cyan"
Start-Sleep 3 Start-Sleep 3

View File

@ -37,11 +37,11 @@ function Invoke-PostUpdateActions {
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) { if (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red" Write-ToLog "-> WinGet is not installed/up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "red"
Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation) $true Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation)
} }
elseif ($WinGetAvailableVersion -match "-pre") { elseif ($WinGetAvailableVersion -match "-pre") {
Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow" Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow"
Update-StoreApps $true Update-StoreApps
} }
else { else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "green" Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "green"
@ -146,6 +146,7 @@ function Invoke-PostUpdateActions {
#Remove old functions / files #Remove old functions / files
$FileNames = @( $FileNames = @(
"$WorkingDir\functions\Start-Init.ps1",
"$WorkingDir\functions\Get-Policies.ps1", "$WorkingDir\functions\Get-Policies.ps1",
"$WorkingDir\functions\Get-WAUCurrentVersion.ps1", "$WorkingDir\functions\Get-WAUCurrentVersion.ps1",
"$WorkingDir\functions\Get-WAUUpdateStatus.ps1", "$WorkingDir\functions\Get-WAUUpdateStatus.ps1",

View File

@ -1,65 +0,0 @@
# Initialisation
function Start-Init {
#Config console output encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
$Script:ProgressPreference = 'SilentlyContinue'
$caller = Get-ChildItem $MyInvocation.PSCommandPath | Select-Object -Expand Name
if ($caller -eq "Winget-Upgrade.ps1") {
#Log Header
$Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
$Log | Write-host
#Logs initialisation
$Script:LogFile = "$WorkingDir\logs\updates.log"
}
elseif ($caller -eq "Winget-AutoUpdate-Install.ps1") {
$Script:LogFile = "$WingetUpdatePath\logs\updates.log"
}
if (!(Test-Path $LogFile)) {
#Create file if doesn't exist
New-Item -ItemType File -Path $LogFile -Force | Out-Null
#Set ACL for users on logfile
$NewAcl = Get-Acl -Path $LogFile
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
$fileSystemRights = "Modify"
$type = "Allow"
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $LogFile -AclObject $NewAcl
}
elseif ((Test-Path $LogFile) -and ($caller -eq "Winget-AutoUpdate-Install.ps1")) {
#Set ACL for users on logfile
$NewAcl = Get-Acl -Path $LogFile
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
$fileSystemRights = "Modify"
$type = "Allow"
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $LogFile -AclObject $NewAcl
}
#Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink
if ((Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and !(Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log")) {
Write-host "`nCreating SymLink for log file (WAU-updates) in Intune Management Extension log folder" -ForegroundColor Yellow
New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null
}
#Check if Intune Management Extension Logs folder and WAU-install.log exists, make symlink
if ((Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and (Test-Path "$WorkingDir\logs\install.log") -and !(Test-Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log")) {
Write-host "`nCreating SymLink for log file (WAU-install) in Intune Management Extension log folder" -ForegroundColor Yellow
New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value "$WorkingDir\logs\install.log" -Force -ErrorAction SilentlyContinue | Out-Null
}
if ($caller -eq "Winget-Upgrade.ps1") {
#Log file
$Log | out-file -filepath $LogFile -Append
}
}

View File

@ -1,16 +1,15 @@
#Function to force an upgrade of Store Apps #Function to force an upgrade of Store Apps
Function Update-StoreApps ($Log = $false) { Function Update-StoreApps {
$force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..." $force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..."
$fail_string = "-> ...something went wrong!" $fail_string = "-> ...something went wrong!"
#If not WSB or Server, upgrade Microsoft Store Apps! #If not WSB or Server, upgrade Microsoft Store Apps!
if (!(Test-Path "${env:SystemDrive}\Users\WDAGUtilityAccount") -and (Get-CimInstance Win32_OperatingSystem).Caption -notmatch "Windows Server") { if (!(Test-Path "${env:SystemDrive}\Users\WDAGUtilityAccount") -and (Get-CimInstance Win32_OperatingSystem).Caption -notmatch "Windows Server") {
switch ($Log) {
$true {Write-ToLog $force_string "yellow"} Write-ToLog $force_string "yellow"
Default {Write-Host $force_string -ForegroundColor Yellow}
}
try { try {
$namespaceName = "root\cimv2\mdm\dmmap" $namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_EnterpriseModernAppManagement_AppManagement01" $className = "MDM_EnterpriseModernAppManagement_AppManagement01"
@ -19,10 +18,7 @@ Function Update-StoreApps ($Log = $false) {
return $true return $true
} }
catch { catch {
switch ($Log) { Write-ToLog $fail_string "red"
$true {Write-ToLog $fail_string "red"}
Default {Write-Host $fail_string -ForegroundColor Red}
}
return $false return $false
} }
} }

View File

@ -1,51 +1,36 @@
#Function to download and update WinGet #Function to download and update WinGet
Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath, $Log = $false) { Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath) {
$download_string = "-> Downloading WinGet MSIXBundle for App Installer..." $download_string = "-> Downloading WinGet MSIXBundle for App Installer..."
$install_string = "-> Installing WinGet MSIXBundle for App Installer..." $install_string = "-> Installing WinGet MSIXBundle for App Installer..."
$success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully" $success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully"
$reset_string = "-> WinGet sources reset." $reset_string = "-> WinGet sources reset."
$fail_string = "-> Failed to install WinGet MSIXBundle for App Installer..." $fail_string = "-> Failed to install WinGet MSIXBundle for App Installer..."
#Download WinGet MSIXBundle #Download WinGet MSIXBundle
switch ($Log) { Write-ToLog $download_string
$true {Write-ToLog $download_string}
Default {Write-Host $download_string}
}
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient = New-Object System.Net.WebClient $WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") $WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
#Install WinGet MSIXBundle in SYSTEM context #Install WinGet MSIXBundle in SYSTEM context
try { try {
switch ($Log) { Write-ToLog $install_string
$true {Write-ToLog $install_string}
Default {Write-Host $install_string}
}
Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
switch ($Log) { Write-ToLog $success_string "green"
$true {Write-ToLog $success_string "green"}
Default {Write-host $success_string -ForegroundColor Green}
}
#Reset WinGet Sources #Reset WinGet Sources
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
if ($ResolveWingetPath) { if ($ResolveWingetPath) {
switch ($Log) { Write-ToLog $reset_string "green"
$true {Write-ToLog $reset_string "green"}
Default {Write-Host $reset_string -ForegroundColor Green}
}
#If multiple version, pick last one #If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path $WingetPath = $ResolveWingetPath[-1].Path
& $WingetPath source reset --force & $WingetPath source reset --force
} }
} }
catch { catch {
switch ($Log) { Write-ToLog $fail_string "red"
$true {Write-ToLog $fail_string "red"}
Default {Write-Host $fail_string -ForegroundColor Red}
}
Update-StoreApps Update-StoreApps
} }

View File

@ -1,9 +1,36 @@
#Write to Log Function #Write to Log Function
function Write-ToLog ($LogMsg, $LogColor = "White") { function Write-ToLog {
#Get log [CmdletBinding()]
$Log = "$(Get-Date -UFormat "%T") - $LogMsg" param(
[Parameter()] [String] $LogMsg,
[Parameter()] [String] $LogColor = "White",
[Parameter()] [Switch] $IsHeader = $false
)
#Create file if doesn't exist
if (!(Test-Path $LogFile)) {
New-Item -ItemType File -Path $LogFile -Force | Out-Null
#Set ACL for users on logfile
$NewAcl = Get-Acl -Path $LogFile
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
$fileSystemRights = "Modify"
$type = "Allow"
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $LogFile -AclObject $NewAcl
}
#If header requested
if ($IsHeader) {
$Log = "`n##################################################`n# $LogMsg - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
}
else {
$Log = "$(Get-Date -UFormat "%T") - $LogMsg"
}
#Echo log #Echo log
$Log | Write-host -ForegroundColor $LogColor $Log | Write-host -ForegroundColor $LogColor