2022-03-14 13:55:02 +00:00
|
|
|
#Initialisation
|
|
|
|
|
|
|
|
function Start-Init {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
#Config console output encoding
|
|
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
|
2023-01-12 20:16:03 +00:00
|
|
|
# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
|
|
|
|
[int32] $MaxLogFiles = 3
|
|
|
|
|
|
|
|
# Maximum size of log file.
|
|
|
|
[int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB
|
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
#Log Header
|
2022-03-26 08:22:49 +00:00
|
|
|
$Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"
|
2022-03-14 13:55:02 +00:00
|
|
|
$Log | Write-host
|
|
|
|
|
2022-10-08 00:18:46 +00:00
|
|
|
#Logs initialisation
|
|
|
|
$Script:LogFile = "$WorkingDir\logs\updates.log"
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-10-08 00:18:46 +00:00
|
|
|
if (!(Test-Path $LogFile)) {
|
|
|
|
#Create file if doesn't exist
|
|
|
|
New-Item -ItemType File -Path $LogFile -Force
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-10-08 00:18:46 +00:00
|
|
|
#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
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2023-01-12 20:16:03 +00:00
|
|
|
#LogRotation if System
|
|
|
|
if ($IsSystem) {
|
|
|
|
Invoke-LogRotation $LogFile $MaxLogFiles $MaxLogSize
|
|
|
|
}
|
|
|
|
|
2022-10-08 00:18:46 +00:00
|
|
|
#Log file
|
|
|
|
$Log | out-file -filepath $LogFile -Append
|
|
|
|
|
2022-10-26 22:49:10 +00:00
|
|
|
}
|