I wanted to share a script I wrote a while back that will remotely install MSU patches. It requires PSTools to work and I ran this using Powershell 3.0.
This little method requires using two scripts, one that will install the MSU files locally, while the main script will execute the local installer remotely. It follows this process:
-The main script is ran and passed a path to where the MSU files are located at along with the secondary script, along with a textfile containing a list of computers.
The computer list should look like the following:
Computer1
CoolComputer252
ILikePancakes510
-The main script will robocopy all the files to the remote computer, this include the MSU patches and the secondary script.
-The main script subsequently runs PSExec on the secondary script which will install all the MSU patches under the system account.
-The secondary script then proceeds to taskkill itself to ensure the primary script starts installing patches on the next computer in the array.
It is also imperative that you have the proper credentials to remotely access the computer else this will fail.
Here is the first script.
Function Install_Patches([string]$path, [string]$computerList) { Get-Content $computerList $arrayOfComputers = @() $arrayOfComputers = (Get-Content $computerList) -split "`n" #Copy the files to each computer foreach($computer in $arrayOfComputers) { $OutputLocation = "\\" + $computer + "\C$\<LOCATION>" #path from the first paramater robocopy $path $OutputLocation /e /s Write-Host "Transfer completed for $computer" #patch the computer psexec $path -s cmd.exe /c "echo . | powershell.exe -executionpolicy bypass -file c:\<LOCATION>\CMDMSUInstall.ps1" Write-Host "Patching completed for $computer" } }
Here is the second script:
cd C:\<LOCATION> $path = "C:\<LOCATION>" $files = Get-ChildItem $path -Recurse $msus = $files | ? {$_.extension -eq ".msu"} foreach($msu in $msus) { $fullname = $msu.FullName $fullname = "`"" + $fullname + "`"" $parameters = $fullname + " /quiet /norestart" $install = [System.Diagnostics.Process]::Start( "wusa",$parameters ) $install.WaitForExit() } #kill itself to ensure it goes back to the next computer object taskkill /f /im PSEXESVC.exe
Additonally, make sure you modify the location of where the patches will be copied too and where the local script is ran at.