Hi all,

I’m trying to get a powershell script put out in our environment to forcibly install windows updates and reboot, silent to the user.

Before anyone jumps on the WSUS bandwagon, it works in some cases, but as we all know it is well flawed too.

What I want to get running is essentially three steps

1- install the PSWindowsUpdate module, and skip this step if it is already installed.

2- run the command “Install-WindowsUpdate -AcceptAll -AutoReboot”

The problems I am running into:

With step 1, no matter the options or flags I choose (like -force and/or -confirm:$false), I still get prompted to install the NuGet provider. I want this to be accepted automatically without any prompts.

With step 2, I have had to make the command “powershell.exe -executionpolicy bypass Install-WindowsUpdate -AcceptAll -AutoReboot” to avoid it erroring out due to the exeecution policy.

I want to get this all wrapped up into a pretty little .ps1 file, but I need to get step 1 working completely silent to the users before I push the script and schedule it with task scheduler…

I’d appreciate any help I can get.

Thanks

8 Spice ups

Can you please post the actual code you are using?

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

You can run a

Get-PackageProvider nuget

and if that is not the right version or not there you can install it.

# you may ot may not need the TLS line depending on your environment
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet
1 Spice up

So, in theory, I should be able to throw this in a PS1 and have it work?

Install-PackageProvider -Name NuGet
Install-Module PSWindowsUpdate -force -confirm:$false
Install-WindowsUpdate -AcceptAll -AutoReboot

The version of NuGet installed with the command above is supported.

Where will I put the execution policy bypass switch?

Thanks

after your first 3 command lines

Correction. In place of your 3rd line.

that has to be when you call the ps1 file.
Or you have 2 ps1 files one is a helper script that calls the other.

e.g.

powershell.exe -executionpolicy bypass -file "PATH_TO_THE_.ps1"
2 Spice ups

For more information about adjusting the execution policy for your PowerShell scripts to work and other great tips, you may be interested in checking the following guide https://www.hyper-v.io/powershell-commands-scripts-not-work-can-fix/ .