PowerShell – Apply Multiple Hotfixes Automatically

If you have ever had the need to apply multiple hotfixes to a server, this handy little script will apply all hotfixes located within a network share of your choice (simply download the MSU files to this location). The progress of each installation is displayed and you will be prompted to reboot post patching.


$HotfixTemp = 'C:\Temp\Hotfixes'
If (!(Test-Path -Path $HotfixTemp))
	New-Item -ItemType Directory -Path 'C:\Temp\Hotfixes\'
Set-Location -Path $HotfixTemp
Get-ChildItem -Path $HotfixDir | Copy-Item -Destination $HotfixTemp -Include *.msu
$Hotfixes = Get-ChildItem $HotfixTemp | Where-Object { $_.Name -like '*.msu' } | Select Name | Sort-Object

foreach ($Hotfix in $Hotfixes.name)
	$NextHotfix = ("$hotfixtemp" + "\$Hotfix" + " /quiet" + " /norestart")
	Start-Process C:\Windows\System32\wusa.exe -ArgumentList $NextHotfix
	while ((Get-Process wusa -ErrorAction 'SilentlyContinue') -ne $Null)
		for ($i = 1; $i -le 10; $i++)
			write-progress -id 1 -activity "Processing $Hotfix" -status "Installing..." -percentComplete ($i * 10);
			sleep 1;
Write-Host -ForegroundColor 'Green' "Patching completed. Please reboot for updates to take effect"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s