Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module PSWindowsUpdate
- # Path to log file
- $LogPath = "C:\Scripts\Logs\Update-Windows-$(get-date -Format "yyyy-MM-dd HH-mm-ss").txt"
- # Function to log messages
- function Write-Log {
- param ([string]$Message)
- Add-Content -Path $LogPath -Value "$Message" -Encoding unicode
- }
- Write-Log "Starting Windows Update process."
- try {
- # Check for updates
- $Updates = Get-WindowsUpdate -AcceptAll -IgnoreReboot
- if ($Updates) {
- Write-Log "Updates found: $($Updates.Count). Installing updates."
- Install-WindowsUpdate -AcceptAll -AutoReboot -Verbose | Tee-Object -FilePath $LogPath -Append
- Write-Log "Updates installed successfully."
- } else {
- Write-Log "No updates available at this time."
- }
- }
- catch {
- Write-Log "Error during update process"
- }
Advertisement
Add Comment
Please, Sign In to add comment