ou can automate and execute Windows Update with PowerShell script.

This is a simple example script to install and reboot the server after patching.

Feel free to change the last line of the code to not reboot the server after completion if that’s necessary.

If you have Powershell version 5 would be easier.

1) The first thing you need to do is confirm the version of PowerShell you have:
$PSVersionTable.PSVersion

If version 5 or above, confirm you are running PowerShell as administrator and continue with:
Install-Module PSWindowsUpdate
Get-Command –module PSWindowsUpdate

Then you will need to register to use the Microsoft Update Service, not just the default Windows Update Service.
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d

Then run:
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot

Below is the script for other versions other them 5 which is above.
================================================================================

# Download and Install Windows Patches with Reboot
# Script version 1.0
# Date : 08/25/2016
# Michael Goulart

$waar = 1 -eq 1
$Session = New-Object -com "Microsoft.Update.Session"
$Search = $Session.CreateUpdateSearcher()
$SearchResults = $Search.Search("IsInstalled=0 and IsHidden=0")
$DownloadCollection = New-Object -com "Microsoft.Update.UpdateColl"
$SearchResults.Updates | ForEach-Object {
if ($_.InstallationBehavior.CanRequestUserInput -ne $waar) {
$DownloadCollection.Add($_) | Out-Null
}
}
if ($($SearchResults.Updates.Count -gt 0)) {
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $DownloadCollection
$Downloader.Download()
}

$objServiceManager = New-Object -ComObject "Microsoft.Update.ServiceManager"
$objSession = New-Object -ComObject "Microsoft.Update.Session"
$objSearcher = $objSession.CreateUpdateSearcher()
Foreach ($objService in $objServiceManager.Services){
if($ServiceID){
if($objService.ServiceID -eq $ServiceID){
$objSearcher.ServiceID = $ServiceID
$objSearcher.ServerSelection = 3
$serviceName = $objService.Name
}
}else{
if($objService.IsDefaultAUService -eq $True){
$serviceName = $objService.Name
}
}
}
$objCollection = New-Object -ComObject "Microsoft.Update.UpdateColl"
$objResults = $objSearcher.Search("IsInstalled=0")
$FoundUpdatesToDownload = $objResults.Updates.count
if ($objResults.Updates.count -gt 0){
foreach($Update in $objResults.Updates){
if($Update.EulaAccepted -eq 0 ){
$Update.AcceptEula()
}
if($Update.isdownloaded -eq 0){
$objCollectionTmp = New-Object -ComObject "Microsoft.Update.UpdateColl"
$objCollectionTmp.Add($Update) | out-null
$Downloader = $objSession.CreateUpdateDownloader()
$Downloader.Updates = $objCollectionTmp
}
}
$objCollectionTmp = New-Object -ComObject "Microsoft.Update.UpdateColl"
foreach($Update in $objResults.Updates){
$objCollectionTmp.Add($Update) | out-null
}
$objInstaller = $objSession.CreateUpdateInstaller()
$objInstaller.Updates = $objCollectionTmp
$InstallResult = $objInstaller.Install()
}

shutdown -r -t 30 -c "Restart after windows update"

GitHub
https://github.com/mgoular/DonwloadInstallPatches

Technet
https://gallery.technet.microsoft.com/scriptcenter/and-Install-Patches-with-831d7f60


31 Comments

Jack · September 11, 2017 at 12:10 PM

Ԝould Turning intⲟ A Freelawnce Paralegal Be A Good Choice Foг You?

    brgeek · September 12, 2017 at 12:16 PM

    Hi, unfortunately, this is comment is not in the scope of the subject 🙂 But I appreciate anyways 🙂 Bye

maids in the house · September 15, 2017 at 3:13 PM

I love what you guys are usually up too. This kind of clever
work and reporting! Keep up the good works guys I’ve added you guys
to blogroll.

    brgeek · September 18, 2017 at 1:08 PM

    Thanks for following and wish all the best with your website!

Lavern · September 17, 2017 at 11:19 AM

Hi! Do you use Twitter? I’d like to follow you if that would be ok.
I’m definitely enjoying your blog and look forward to
new updates.

    brgeek · September 18, 2017 at 1:06 PM

    Hi, Lavern, I do have a twitter but its kind of deactivated for the moment only using to subscribe on the giveaways for the counter strike championship majors which I like to see =), so better follow-up here or if you prefer follow _Rzero, but can’t guarantee the content there 😀 lately I am doing some octoblu integration that uses twitter so you can see strange messages there too ! Enjoy

maid for cleaning houses · September 19, 2017 at 10:18 AM

Yes! Finally someone writes about maid services.

Georgia Post · September 24, 2017 at 2:37 AM

Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I get actually
enjoyed account your blog posts. Any way I’ll be subscribing
to your augment and even I achievement you access consistently rapidly.

Grant Daughtry · September 25, 2017 at 12:39 AM

Hi there, just became alert to your blog through Google,
and found that it is really informative. I am gonna
watch out for brussels. I’ll be grateful if
you continue this in future. A lot of people will be benefited from your writing.
Cheers!

qq poker · November 3, 2017 at 10:40 AM

Yoս shоuld take part in a contest for one of
tһe greatest ԝebsites on thhe net. I will recommend this site! http://issuu.com/mcfaddendthnvtddlc/docs/main_pokerqq_lebih_hebat_loh_rasaka

    brgeek · January 5, 2018 at 11:36 AM

    Thanks for the recommendation !

agen Poker qq · November 6, 2017 at 5:39 AM

Awesomе bⅼog! Is yoսr theme custo made or did you download it from ѕomewhere?
A themе like yours with a few simple tweeks would гeally maкe my blog shine.
Plеase let me ҝnow whhere you gοt your design. Βless you http://www.Purevolume.com/listeners/assortedelation09/posts/6857982/bermain+PokerQQ+lebih+asyik+loh%2C+rasakan+perbedaanya%21

    brgeek · January 5, 2018 at 11:35 AM

    Hi , this theme come with the WordPress really simple to get installed !
    Look out for Hestia Template.

write my paper for me cheap · November 24, 2017 at 11:15 PM

Hi! I understand this is sort of off-topic however I had to ask.
Does building a well-established blog like yours require a massive amount work?
I’m completely new to operating a blog but I do write in my
journal every day. I’d like to start a blog so
I can easily share my experience and views online.

Please let me know if you have any kind of recommendations or tips for brand new aspiring blog owners.

Thankyou!

    brgeek · January 5, 2018 at 11:33 AM

    Hi , it depends on your availability I must say , but if you have a schedule that helps a lot.
    I dont have a regular schedule so I do write when my time permits me to do it , and this is a side project for me.
    Please send me your Blog address as soon as you have it ! Happy blogging !

Jayson · February 27, 2018 at 1:41 AM

Diferentes meios, para diferentes públicos.

http://cswygwzj.com/Comment/html/?231430.Html · May 30, 2018 at 7:53 PM

Hello There. I discovered your weblog the usage of msn. That is a very smartly written article.
I will make sure to bookmark it and come back to read extra of your useful information. Thank you for the
post. I will definitely comeback.

https://goo.gl/ · June 2, 2018 at 10:16 AM

I used to be recommended this web site by way of my cousin. I’m
no longer positive whether this submit is written by
him as nobody else recognize such special approximately my problem.

You’re wonderful! Thanks!

https://chuabenhthan.vn/ · June 6, 2018 at 9:29 PM

Awesome issues here. I am very happy to see your article.
Thank you a lot and I am taking a look forward to touch you.
Will you please drop me a mail?

goo.gl · June 8, 2018 at 7:01 AM

Hi there, I enjoy reading all of your article. I wanted to write a little
comment to support you.

chuabenhthan.vn · June 9, 2018 at 10:38 PM

I blog often and I really thank you for your content.
Your article has really peaked my interest. I am going to bookmark your
website and keep checking for new details about once a week.
I opted in for your RSS feed as well.

cel mai prost blogger · June 10, 2018 at 7:34 AM

I am in fact happy to read this weblog posts which contains lots of useful data, thanks for providing these kinds of statistics.

chuabenhthan.vn · June 10, 2018 at 8:12 AM

Great goods from you, man. I’ve be mindful your stuff previous to
and you’re simply too magnificent. I actually like what
you have bought here, certainly like what you are saying and the
way wherein you are saying it. You make it entertaining and you continue to care for to
keep it smart. I can not wait to read far more from you. That is really a terrific
web site.

chuabenhthan.vn · June 12, 2018 at 1:23 AM

You are so cool! I do not think I have read anything like this before.

So wonderful to discover another person with unique
thoughts on this issue. Really.. thank you for starting this up.

This site is something that is required on the web, someone with a bit of originality!

goo.gl · June 12, 2018 at 7:41 AM

Terrific article! This is the kind of information that are meant to
be shared across the internet. Shame on the search engines for no longer positioning this put up upper!

Come on over and discuss with my site . Thank you =)

essay writer · June 29, 2018 at 6:31 PM

Pretty component of content. I simply stumbled upon your blog and in accession capital to say that I acquire in fact loved account your weblog posts.
Any way I will be subscribing to your feeds and even I fulfillment you access consistently
quickly. https://sweacarolina.com/groups/how-to-write-a-thematic-essay/

http://poradna.smartpozicky.sk/42529/best-ways-to-take-advantage-of-low-carb-diets-today-br · July 1, 2018 at 4:01 PM

Heⅼlo it’s me, I am also visiting this web page on a regulаr basis, this web sitе iis genuinely nice ɑnd
the visitors are in fact sharing good thoughts.

بلوجر · July 7, 2018 at 5:45 PM

I was suggested this blog by way of my cousin. I am not
sure whether this submit is written by him as no one else realize such targeted approximately my
problem. You are amazing! Thank you!

mua ngay · July 21, 2018 at 5:07 PM

Good web site you have got here.. It’s difficult to find high quality writing like yours nowadays.

I honestly appreciate individuals like you! Take care!!

TYRA · January 31, 2019 at 6:24 AM

okay thank you for the information, it gives a solution about this

minecraft · April 30, 2019 at 10:47 PM

Hmm it seems like your blog ate my first comment (it was super long) so
I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.
I as well am an aspiring blog blogger but I’m still new to everything.

Do you have any helpful hints for novice blog writers? I’d definitely appreciate
it.

Leave a Reply to brgeek Cancel reply

Avatar placeholder

Your email address will not be published. Required fields are marked *