Keeping Windows up to date is critical from security point of view. Each month on second Tuesday (aka ‘patch Tuesday’) Microsoft issues critical and recommended security updates and bug fixes which everyone should install. But if you are on a low-bandwidth Internet connection (or none at all), you may grab the updates from Microsoft Download Center and install the msu files manually. However, depending on the number of updates released or for how long you haven’t been installing updates, the number of files to install may grow above 30. To install all these files in a seamless way without any intervention you can harness the power of PowerShell – Windows’ own shell, just like Bash in Linux.
For this you need a small script which you need to run from an elevated PowerShell instance. Here is the script –
$dir = (Get-Item -Path ".\" -Verbose).FullName Foreach($item in (ls $dir *.msu -Name)) { echo $item $item = $dir + "\" + $item wusa $item /quiet /norestart | Out-Null }
Create a file named “install.ps1” (or any other name with .ps1 as extension) in the directory where all your msu files are present and paste this script into it. Open an elevated (run as Administrator) instance of PowerShell and navigate to the directory where the msu files are located (using cd command). Type “.\install.ps1” (this may change depending on what you named your file as) and press enter. It will now install one file at a time and display the name of file currently being installed.
If you get an error like this – “… cannot be loaded because the execution of scripts is disabled on this system”;
run this command and try running the script again –
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
This will enable running of scripts on your computer and you can continue with installing Windows updates.
this is great! thanx alot
LikeLike
Worked perfectly!!
LikeLike
Works great thanks so much
LikeLike
Perfect – thanks!
LikeLike
Thank you very much
LikeLike
nice work bro
LikeLike
What if you need to install an .exe patch?
LikeLike
Stick this at the top of the install script to extract the MSU’s first:
if (Test-Path -Path “.\*.zip”)
{
$dir = (Get-Item -Path “.\” -Verbose).FullName
Foreach($item in (ls $dir *.zip -Name))
{
Expand-Archive $item -DestinationPath “.\”
Remove-Item $item
}
}
LikeLike
This is really helpfull and worked thanks a lot
LikeLike
Hi, nice one.
how does this works with not-needed or already installed msu files ?
LikeLike
How can I use it to run remotely by passing a different machine name
LikeLike
Use Windows Admin Center and then Remote Powershell. 🙂
LikeLike
Hi Harshil
Does this Script install order is one by one or random? and what if the files are in share folder(other server)?
Thanks in advance
LikeLike
I love you man
LikeLike
A one line option would also work:
for %%i in (*.msu) do start /w wusa.exe %%i /norestart /quiet
LikeLike
Very helpful, thank you for posting
LikeLike
I did execute the script succefully but when I check the installed updates I can not see the CAB or MSU listed.
LikeLike
Excelent work
But is possible to add a log file to it?
LikeLike
Hi. Could it be divorced? What file install.ps1? Is it a folder? What directory is this folder? How can I put the script somewhere? I thought I should put it in PowerShell. What does the CD command look like?
LikeLike