{"id":175,"date":"2021-11-12T07:21:00","date_gmt":"2021-11-12T07:21:00","guid":{"rendered":"https:\/\/172.105.20.94\/?p=175"},"modified":"2022-10-21T20:25:27","modified_gmt":"2022-10-22T04:25:27","slug":"force-installing-windows-updates-via-powershell-pswindowupdates","status":"publish","type":"post","link":"https:\/\/tungle.ca\/?p=175","title":{"rendered":"Force installing Windows updates via PowerShell PSWindowUpdates"},"content":{"rendered":"\n<p>F_PSWindowsUpdates.PS1 is shared on \\\\DC1\\Shared<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell line-numbers\"># This is PowerShell script to force on installing Windows Updates via PSWindowsUpdate on Windows machines\n# https:\/\/www.powershellgallery.com\/packages\/PSWindowsUpdate\/2.2.0.2\n# It is created on 2021-10-21\n# Allow PowerShell to be run on Windows machines with PSWindowsUpdate module\nSet-ExecutionPolicy RemoteSigned\n# Installs everything (newest version) along with required modules.\nInstall-Module PSWindowsUpdate\n# Import Module PSWindowsUpdate before running the script\nImport-Module -Name PSWindowsUpdate\n# Force Windows updates are completely downloaded, installed and then restarted. Will check if we have a WSUS server\nInstall-WindowsUpdate -AcceptAll -AutoReboot\n# Send an email after running PSWindowsUpdate command\n# Will send email if the last previous command is successful.\nif ($? -eq $True){\n        # Use this command for TLS requirement\n        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n        # Get machine name\n        $machinename = get-content env:computername\n        # Get current date and time\n        $currentdate = get-date\n        # Get current date and time\n        $currentdate = get-date\n        # SMTP server of Xyz.com&lt;\/p&gt;\n        $SMTP = \"smtp-mail.xyz.com\"\n        # Mail from&lt;\n        $From = \"youremail@xyz.com\"\n        # Rcpt to\n        $To = \"youremail@xyz.com\"# Subject line\n        $Subject = \"Windows updates on $cname\"\n        # Email body\n        $Body = \"Finising running Windows updates on $machinename on $currentdate\"\n        #Create a connection to SMTP Outlook via the port 587&lt;\/p&gt;\n        $Email = New-Object Net.Mail.SmtpClient($SMTP, 587)\n        # Enable SSL for the connection\n        Email.EnableSsl = $true\n        #Log in to xyz mail server with your credential\n        $Email.Credentials = New-Object System.Net.NetworkCredential(\"youremail@xyz.com\", \"yourpassword\");\n        # Send email syntax\n        $Email.Send($From, $To, $Subject, $Body)\n}<\/code><\/pre>\n\n\n\n<p>Assign this script on Task Scheduler.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"763\" height=\"655\" src=\"https:\/\/172.105.20.94\/wp-content\/uploads\/2021\/12\/image-103.png\" alt=\"\" class=\"wp-image-176\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-103.png 763w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-103-300x258.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-103-200x172.png 200w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"278\" src=\"https:\/\/172.105.20.94\/wp-content\/uploads\/2021\/12\/image-104.png\" alt=\"\" class=\"wp-image-177\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-104.png 865w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-104-300x96.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-104-768x247.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-104-200x64.png 200w\" sizes=\"auto, (max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"612\" src=\"https:\/\/172.105.20.94\/wp-content\/uploads\/2021\/12\/image-107.png\" alt=\"\" class=\"wp-image-180\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-107.png 817w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-107-300x225.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-107-768x575.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2021\/12\/image-107-200x150.png 200w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>F_PSWindowsUpdates.PS1 is shared on \\\\DC1\\Shared Assign this script on Task Scheduler.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,7],"tags":[10,12],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-powershell","tag-microsoft","tag-powershell"],"_links":{"self":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":6,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":4313,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions\/4313"}],"wp:attachment":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}