Cmdlet for Detect and install update + reboot

Hi Guys,

I have around 100 servers in a test environment which i need to update on specific days. An GPO is not an option. Is there any script which i can use? What i would like to have are the following:

1. Search for windows updates on WSUS
2. Install all available updates
3. Restart
4. Detect again

Something like "wuauclt /detectnow /reportnow" with an restart option would be perfect -shutdown /r does not work.

It would be even better if i can enter computernames.

Thanks in adcance.
CanSystem AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DevAdminSystem Engineer | .NET Developer | Microsoft MVP | Technical SpeakerCommented:
try read my post
https://www.devadmin.it/2018/11/20/forzare-lesecuzione-degli-aggiornamenti-in-windows-10-e-windows-server-2016-2019/

REM WaitTime 30 minute (1800 sec)
SET WaitTime=1800

REM Scan Updates
%systemroot%\system32\UsoClient.exe StartScan
 
REM Wait scan to complete
timeout /t %WaitTime%

REM Download updates
%systemroot%\system32\UsoClient.exe StartDownload

REM Wait Download to complete
timeout /t %WaitTime%

REM Install updates
%systemroot%\system32\UsoClient.exe StartInstall

REM Wait Install to complete
timeout /t %WaitTime%

REM Restart Computer
shutdown /r /t 0 /c “Restart after force install updates by script”
CanSystem AdministratorAuthor Commented:
Hi,

Unfortunately i dont understand italian. The command i need, needs to do the following :

Check update>Install>Restart if needed>Check update.

Thanks.
DevAdminSystem Engineer | .NET Developer | Microsoft MVP | Technical SpeakerCommented:
You can do with UsoClient do you try the script that I write in my previous answer?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

CanSystem AdministratorAuthor Commented:
Hi Ermanno,

I have tested it. I get a few errors. Please check the attachment.

Thanks.
2019-01-19-13_19_36-Windows-PowerShe.png
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Ermanno provided a CMD batch, not a PowerShell script.
CanSystem AdministratorAuthor Commented:
Hi Qlemo,

Thank you for the info. The bat file works. Yet i have a question about the 1800 seconds. is there any option to continue when the task is done instead of waiting 1800 seconds after every task?
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The issue with the UsoClient is that it is asynchronous, and returns immediately - you don't get any info back when the job is done.
That is also the reason why the script does not have a way to tell  whether there have been updates.

By parsing the update logfille it might be possible to get some state info, but that requires significant effort.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Installation

From novice to tech pro — start learning today.