SPPatchify – CU patch entire farm from one script
Patching can be tedious and time consuming. Why not automate that? Who wants to be awake all night clicking “Next” and watching SP config wizard? So I coded a single PowerShell script to manage the full end-to-end patching process.
The script will …
- Enable PowerShell client remoting. Connects to farm peer machines.
- Autodetect current user password from IIS pools
- Download Microsoft Cumulative Update (CU) media (EXE +CAB) and copy to all servers. Optionally, you can download to the \media\ sub folder manually.
- Stop Distributed Cache (DC)
- Stop SharePoint services
- Run EXE binary in paralle
- Wait for EXE to complete and reboot
- Dismount-SPContentDatabase
- Start SharePoint services
- Run SharePoint Config Wizard serially
- Mount-SPContentDatabase
- Remove Microsoft Cumulative Update (CU) media from peer servers
- Ensure IIS started
- Launch Central Admin with IE
- Reboot current PC
Duration from start to end is incredibly fast. I tested a 4 server SharePoint 2013 farm and ran the entire process in just 45 minutes. Stopping services and dismounting content databases speeds up patching significantly. Automating serial (one-at-time) Configuration Wizard ensures minimal “think time” between steps. Removing manual human process gives higher consistency while mitigating risk of error.
The script uses Get-SPServer to auto detect farm members. That enables CU media copy sideways to peers and the stop/start of SharePoint services. Get-SPContentDatabase is exported to a local CSV file to “snapshot” before patching and later Mount-SPContentDatabase step to present databases again. The big goal isn’t zero downtime, but rather minimal downtime.
The entire farm patching process can be managed from one PowerShell window. Enjoy!
Please leave a comment if you found this helpful.
Get Started
- https://github.com/spjeff/sppatchify
- Extract to “C:\SPPatchify” on any server in the farm
- RDP with farm account and run “C:\SPPatchify\SPPatchify.ps1”
Flow Diagram
Screenshots





Thanks for the great script, i have just 1 question: i try to patch a SharePoint 2010 farm with this script in a powershell 2.0 session. Have you tried that allready? I get CIM errors (Get-CimInstance : The term ‘Get-CimInstance’ is not recognized as the name of a cmdlet) 1 importent thingie: its a windows 2008 server.
Do you have workaround for this?
Hey Arjan!
Have you tried downloading PowerShell 3.0? That would help make this CMD available and should take care of it.
https://blogs.technet.microsoft.com/heyscriptingguy/2012/09/05/powershell-3-0-is-now-available-for-download/
Powershell 3.0 is allready installed on the server, I start it with -version 2, because sp2010 uses only .net 3.5 and lower. When i try to use version 3.0 I get the following error with sharepoint cmdlets: Get-SPServer : Microsoft SharePoint is not supported with version 4.0.30319.34209 of the Microsoft .Net Runtime.
Ahhh, I see. Yes that was a limitation of SP2010 which requires PowerShell V2 https://support.microsoft.com/en-us/kb/2796733
Can you run these cmds OK? “Import-Module WebAdministration; Get-WebApplication” https://melcher.it/2013/03/powershell-list-all-iis-webapplications-net-version-state-identity/
Mind if we move this to a GitHub issue? Easier to track there — https://github.com/spjeff/sppatchify/issues
Go ahead, I don’t mind it at all. i hope i have a working script tomorrow, so I can test it on our test environment, i think it would save me a lot of time this weekend when i do the other 2010 environments.
Please try downloading the latest PS1.
I updated to have two methods for IIS PW detection here. Should work much better on SP2010 and PowerShell v2 now.
https://github.com/spjeff/sppatchify/blob/master/SPPatchify.ps1#L414-L441
Why do you dismount the content databases and mount them afterwards?
I think the drawing is cool, but I would prefer, if showed the difference between installation the binaries and actually running the PSConfig
Hey Michael!
Dismounting content DBs helps PS Config Wizard run faster. No content, complete wizard, then introduce content back. Helps a LOT of large farms with a high # servers or # databases.
Please explain the difference you’d like to see. I don’t follow here. The LOG records times for every stage, but my experience has been EXE goes about 15 minutes and Config Wizard closer to 30. Ymmv.
Cheers!
Hi Jeff
This script looks fantastic, but unfortunately really doesn’t seem to support 2010 on 2008 R2 as is, does it?
Some issues I’ve found:
– robocopy /j switch doesn’t exist until 2012, so fails under 2008 R2
– many parts of the script need PowerShell 3 to support the appropriate commands/methods, but SharePoint 2010 shell commands need to run forced to PS 2.0, as a result there’s errors throughout. This is what I’m seeing:
===== Copy EXE ===== 08/26/2016 17:29:32
IndexOf : Method invocation failed because [System.Object[]] doesn’t contain a
method named ‘IndexOf’.
At C:DeploysSPPatchifySPPatchify.ps1:869 char:23
After Robocopy finishes (by removing the /j from the switches in the script):
replace : Method invocation failed because [System.Object[]] doesn’t contain a
method named ‘replace’.
At C:DeploysSPPatchifySPPatchify.ps1:918 char:23
Followed by:
cmdlet Write-Progress at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Status:
Just wondered if you’d actually ever got this to work / tested fully on SP2010/2008R2?
Thanks!
@spjeff:disqus Can you help me by providing a script that does not dismount the content DB. Thanks
Hi Rolando! Why not take the DBs offline briefly? This step reduces overall downtime on larger farms by completing the patch sooner.
After downloading the PS1 locally you can comment out lines 1036 and 1040 (ChangeContent) with a leading # symbol so those two lines never run and databases never Dismount/Mount. That would do the trick.
https://github.com/spjeff/sppatchify/blob/master/SPPatchify.ps1#L1036
https://github.com/spjeff/sppatchify/blob/master/SPPatchify.ps1#L1040
Added support for online databases with “-onlineContent” cmd line switch.
Getting this when running it onn SP13 farm ??!
Product = PROJ15
Download CU Media to media – PROJ15
———
0 jun 2017[default] <==
1 maj 2017
2 apr 2017
3 mar 2017
4 jan 2017
5 dec 2016
6 nov 2016
7 okt 2016
8 sep 2016
9 aug 2016
10 jul 2016
11 jun 2016
12 maj 2016
13 apr 2016
14 mar 2016
15 feb 2016
16 jan 2016
17 SP1 2015
Select month. Press [enter] for default:
HALT – have Project Server farm and media folder missing PRJ. Download correc
t media and try again.
Transcript stopped, output file is C:SPPatchifylogSPPatchify-2017-07-03-07-3
0-29.txt
Great catch Wiper! I updated the code to move *PROJ* halt check down after the download step.
Please download the latest version at https://github.com/spjeff/sppatchify/ and run a fresh test. Should be all set.
Hi Jeff – still reported as PROJ15 – and downloading this:
PROJ15 https://download.microsoft.com/download/F/7/A/F7A09DD7-4279-48E6-9875-B60232017D2D/ubersrvprj2013…
PROJ15 https://download.microsoft.com/download/F/7/A/F7A09DD7-4279-48E6-9875-B60232017D2D/ubersrvprj_1.cab
PROJ15 https://download.microsoft.com/download/F/7/A/F7A09DD7-4279-48E6-9875-B60232017D2D/ubersrvprj_2.cab
Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you
have the appropriate permissions to access the database before trying again.
Could you please help me to find a solution?
I’m sure that i’m using the farm admin account
Does anybody has a solution for this problem cause i’m also facing this errormessage.
First, must say pretty awesome script!
Ran the latest SPPatchify script Nov 2017 — in the end, for some reason, the content databases did not get mounted, nor were the content datbases ‘upgraded’?
Just ran the .sppatchify.ps1 from beginning to end.
Want to email me the LOG file?
Curious to see if it has any errrors. Yes, it should Mount and Upgrade the Content database.
Is there a particular email address?
Great job Jeff. This is the second most helpful script after the AutoSPInstaller. I just tried it on a brand-new SP subscription Edition on Windows server 2022 and worked without any issues. The only thing I notice it was not able to run the PSConfig on the local server I was running the script from, but it could be something else and not the PS. I also have to patch the local server manually, but it took care of all other servers in the farm.
Thanks again.
What all did you have to do to make it work with SE?
If anyone has this running for SE, what did you need to change to get it to work?