Monday, August 10, 2015

Powershell Script - Push-Patch - remote installation for KB hotfix, MSI, MSU, or EXE files

Here's a wickedly useful function I threw together based on a strong need to push emergency patches to thousands of servers without the standard route of using a patching deployment system like SCCM, WSUS, Altiris, or HPSA.  All of these tools have their strengths and are generally considered superior to just manually pushing patches, but the sheer versatility of ease of being able to quickly deploy patches is what I required to make tight patching deadlines.

I recommend using this function with Get-HotFix, or Get-WmiObject -class Win32_product for a list of installed patches/software to determine if installation is needed and/or was successful.  You can also come in after the push and look at the log files on the servers in an automated fashion to see how things went.

This script does require PSRemoting to be enabled on target servers, which is true by default on all Windows Server 2012 R2 installs, but needs to be turned on either by GPO or by hand on previous versions.  There's a built in workaround if you pull down PSExec which will work on older servers without PSRemoting.

3 comments:

PIIL said...

Wonderful script Bryan.
Thanks a lot for this.
However I am getting the following error, could you please advice?
Windows update could not be installed because of error 2147942405 "Access is denied."

Bryan Vine said...

Make sure the account you are running as is also a local administrator on the remote server. Also look at the log file created in the default temp location on the remote server, it should have more details. You might need to tweak the install parameters for certain patches.

PIIL said...

Thanks Bryan for the quick response.
Yes, the account is a local admin on the target machine.
Regarding the generated log file, unable to read it using notepad as it is showing as follows.

ø ø ø ! À¬ t D ßf
“ €% ‡Í c ÕÐ Zb (
@ t z r e s . d l l , - 2 6 2
@ t z r e s . d l l , - 2 6 1 Äÿÿÿ ` êAÆÒÐ 6¾& žiÈb ÕÐ W U S A 5 9 5 6 C : \ T E M P \ W i n d o w s 8 . 1 - K B 2 9 8 8 9 4 8 - x 6 4 . m s u - i n s t a l l . l o g ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ