Reboot is needed, check registry key value with Powershell and send email
# the script is scheduled every morning at 9:00, by calling
#powershell -executionpolicy Bypass -File \\AD-DOMAIN-FQDN-OR-NETBIOS\sysvol\DOMAIN\scripts\SCRIPT.PS1
#
$rebootcheck = Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -Name RebootCheckRequired
if ($rebootcheck.RebootCheckRequired -eq 1) {
write-output "reboot needed"
$mailfrom = "email@email.com"
$mailto = "email@email.com"
$mailserver = "SmtpSERVER.email.com"
$mailusername = "domain\username"
$subject = "$(hostname) need reboot for updates"
$body = "reboot asap"
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,TLS11,TLS12'
$getpw = ConvertTo-SecureString 'PLAINTEXTPASSWORD' -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($mailusername, $getpw)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
Send-MailMessage -Credential $mycreds -smtpServer $mailserver -UseSsl -from $mailfrom -to $mailto -subject $subject -body $body -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)
}
else {
write-output "reboot not needed"
}
Commenti
Posta un commento