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!  shades_smile 

Please leave a comment if you found this helpful.

 

Get Started

  1. https://github.com/spjeff/sppatchify
  2. Extract to “C:\SPPatchify” on any server in the farm
  3. RDP with farm account and run “C:\SPPatchify\SPPatchify.ps1”

 

Flow Diagram

6

 

Screenshots

image

5

image

image

image

image

References

24 Comments

  1. 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?

      1. 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.

          1. 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.

  2. 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

    1. 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!

  3. 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!

    1. 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

  4. 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

  5. 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

  6. 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.

  7. 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.

Leave a Comment

Return to Top ▲Return to Top ▲