Post

Visualizzazione dei post da settembre, 2022

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 $t...

Powershell screenshot sketch

$i=0  [Reflection.Assembly]::LoadWithPartialName("System.Drawing") function screenshot([Drawing.Rectangle]$bounds, $path) {    $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height    $graphics = [Drawing.Graphics]::FromImage($bmp)    $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)    $bmp.Save($path)    $graphics.Dispose()    $bmp.Dispose() } $bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1894, 895) screenshot $bounds "C:\screen\screenshot$i.png" $i++