2023-03-31 15:56:07 +00:00
|
|
|
# Initialisation
|
2022-03-14 13:55:02 +00:00
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
function Start-Init
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# Config console output encoding
|
|
|
|
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# Workaround for ARM64 (Access Denied / Win32 internal Server error)
|
|
|
|
$Script:ProgressPreference = 'SilentlyContinue'
|
|
|
|
$caller = ((Get-ChildItem -Path $MyInvocation.PSCommandPath).Name)
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
if ($caller -eq 'Winget-Upgrade.ps1')
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# Log Header
|
|
|
|
$Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-Culture).DateTimeFormat.ShortDatePattern)`n##################################################"
|
|
|
|
$Log | Write-Host
|
|
|
|
# Logs initialisation
|
|
|
|
$Script:LogFile = ('{0}\logs\updates.log' -f $WorkingDir)
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
elseif ($caller -eq 'Winget-AutoUpdate-Install.ps1')
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
$Script:LogFile = ('{0}\logs\updates.log' -f $WingetUpdatePath)
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
if (!(Test-Path -Path $LogFile -ErrorAction SilentlyContinue))
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# Create file if doesn't exist
|
|
|
|
$null = (New-Item -ItemType File -Path $LogFile -Force -Confirm:$false)
|
|
|
|
# Set ACL for users on logfile
|
|
|
|
$NewAcl = (Get-Acl -Path $LogFile)
|
|
|
|
$identity = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList 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
|
|
|
|
}
|
2023-09-15 14:38:54 +00:00
|
|
|
elseif ((Test-Path -Path $LogFile -ErrorAction SilentlyContinue) -and ($caller -eq 'Winget-AutoUpdate-Install.ps1'))
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
#Set ACL for users on logfile
|
|
|
|
$NewAcl = (Get-Acl -Path $LogFile)
|
|
|
|
$identity = (New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList 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)
|
|
|
|
$null = (Set-Acl -Path $LogFile -AclObject $NewAcl)
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink
|
2023-09-15 14:38:54 +00:00
|
|
|
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs") -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log"))
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:33:51 +00:00
|
|
|
# Check if Intune Management Extension Logs folder and WAU-install.log exists, make symlink
|
2023-09-15 14:38:54 +00:00
|
|
|
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))
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
}
|
2023-09-15 14:40:37 +00:00
|
|
|
|
2023-09-15 14:38:54 +00:00
|
|
|
if ($caller -eq 'Winget-Upgrade.ps1')
|
2023-09-15 14:33:51 +00:00
|
|
|
{
|
|
|
|
# Log file
|
|
|
|
$Log | Out-File -FilePath $LogFile -Append -Force
|
|
|
|
}
|
2022-10-26 22:49:10 +00:00
|
|
|
}
|