SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL
SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL

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

  • Arjan Rietveld

    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?

  • Pingback: Business case for Minimal Downtime Patching (MDP) | @SPJeff()

  • Michael

    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!

  • Ed Sparks

    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!

  • Rolando N

    @spjeff:disqus Can you help me by providing a script that does not dismount the content DB. Thanks

  • Wiper

    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

  • ADel

    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

  • Michael

    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.

      • Michael

        Is there a particular email address?

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲