function Write-Log param([string]$Message) $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" "$timestamp - $Message"
Write-Log "Starting PowerShell update process..." if ($PSVersionTable.PSVersion.Major -ge 7) try Write-Log "Checking for PowerShell Core update..." $oldVersion = $PSVersionTable.PSVersion.ToString() $result = Update-PowerShell -Stable -PassThru -Force -ErrorAction Stop Write-Log "PowerShell updated from $oldVersion to $($result.NewVersion)" powershell update command
catch $errorMsg = "PowerShell update failed: $_" Write-Log $errorMsg $errors += $errorMsg powershell update command