I recently went through the process of applying the latest SharePoint 2013 Cumulative Update on my multi server SharePoint 2013 Farm. To my surprise, I found the total time to apply the patch (install the bits) took over 5 hours per SharePoint Server. This time doesn’t include running PSConfig which is considered phase 2. My SharePoint 2013 farm is hosted by a Windows 8 Hyper V environment where my VM’s meet the minimum hardware requirements for memory etc. I found that as I started to gracefully terminate other SharePoint services running, the time of subsequent patch runs started to drop tremendously. I suspect the following:
Some of these processes like App Fabric, Search(node runner), etc.. are taking enough CPU time, threads associated with Windows Installer gets put into a longer line waiting for the most popular roller coaster ride which happens to be the CPU. Note: Threads are treated the same as everyone else in terms of thread priority.
Another way of saying this:
By having x # of additional processes running, you increase the # of threads vying for CPU time by x much. Assuming each process threads are at the same priority, each thread will evenly get a slide of Processor time to execute.
For Example: Let’s assume I have 2 processes (process A) and (process B). Process A has 10 run-able threads while Process B has 3 run-able threads. Assuming these 13 threads are at the same priority, each thread would theoretically receive one-thirteenth of CPU time.
I wrote a Power Shell script to automate and speed up the install of a Cumulative Update on SharePoint 2013. This Power Shell script improved my patch time from 5 hours to 30 minutes. The patch performs the following steps:
1. Disable the IISAdmin and SPTimerV4 service
2. Shut down IIS Admin and Timer Services if they are running
3. Give you the option to Pause the Search Service Application (see search notes below)
4. Stop Search Services (see search notes below)
5. Install the patch in passive mode (No user interaction required but will witness the patch install in the UI)
Note: Power Shell should remain open in the background while patch is running
6. Upon completion of the patch, the Power Shell script, services in step 1 are set to Automatic
7. Starts up IIS Admin and Timer Services
8. Starts up Search Services
9. Resume the Search Service Application if it was paused
10. Finally, the script will display the Start Time and End Time for patch install
Search Notes:
- This script will only stop Search SharePoint Services if they are running
- This script will only pause the Search Service Application upon user input
- This script will only start Search SharePoint Services if they were stopped
- This script will only resume the Search Service Application if it was paused
Important: I recommend pausing the Search Service Application for several reasons but primarily so that Search services aren’t being shutdown during a Full, Incremental, or Continuous Crawl. I made this an option because a SharePoint Admin can run the patch simultaneously on multiple SharePoint servers and may prefer to manually pause/resume the Search Service Application.
Instructions for Running the Power Shell Script
In order to run the script, save the flow script to a text editor like notepad. Save the file with a .ps1 extension to a folder on the SharePoint Server. Drop the SharePoint cumulative update in the same folder as the script. In my example, I created a scripts folder where I dropped the powershell script and the cumulative update.
For Example:
Important: Only one update should be placed here and the file extension should be .exe.
Finally, to run the script from c:\scripts using SharePoint Management Shell. This script is tested on Windows 2012 running SharePoint 2013.
Example Screenshot – during patching it looks like:
Example Screenshot – Patching is complete!
Updated Script 4/4/13 1:41 AM (CST). Thanks to Scott Manning for script validation efforts with appfabric.
Updated Script 4/2/13 2:10 PM (CST). Thanks to Jon Waite for script validation efforts.
Updated Script 8/31/13 10:00 AM (CST). Corrected an issue with starting script and removed appfabric shutdown/start up failed logic. Thx for the feedback!
Updated Script 9/7/15 11:05 AM (CST). Removed /passive switch to expose errors during patching
Script is below, start copying and enjoy!
<# ==============================================================
//
// Microsoft provides programming examples for illustration only,
// without warranty either expressed or implied, including, but not
// limited to, the implied warranties of merchantability and/or
// fitness for a particular purpose.
//
// This sample assumes that you are familiar with the programming
// language being demonstrated and the tools used to create and debug
// procedures. Microsoft support professionals can help explain the
// functionality of a particular procedure, but they will not modify
// these examples to provide added functionality or construct
// procedures to meet your specific needs. If you have limited
// programming experience, you may want to contact a Microsoft
// Certified Partner or the Microsoft fee-based consulting line at
// (800) 936-5200 .
//
// For more information about Microsoft Certified Partners, please
// visit the following Microsoft Web site:
// https://partner.microsoft.com/global/30000104
//
// Author: Russ Maxwell (russmax@microsoft.com)
//
// ---------------------------------------------------------- #>
###########################
##Ensure Patch is Present##
###########################
$patchfile = Get-ChildItem | where{$_.Extension -eq ".exe"}
if($patchfile -eq $null)
{
Write-Host "Unable to retrieve the file. Exiting Script" -ForegroundColor Red
Return
}
########################
##Stop Search Services##
########################
##Checking Search services##
$srchctr = 1
$srch4srvctr = 1
$srch5srvctr = 1
$srv4 = get-service "OSearch15"
$srv5 = get-service "SPSearchHostController"
If(($srv4.status -eq "Running") -or ($srv5.status-eq "Running"))
{
Write-Host "Choose 1 to Pause Search Service Application" -ForegroundColor Cyan
Write-Host "Choose 2 to leave Search Service Application running" -ForegroundColor Cyan
$searchappresult = Read-Host "Press 1 or 2 and hit enter"
Write-Host
if($searchappresult -eq 1)
{
$srchctr = 2
Write-Host "Pausing the Search Service Application" -foregroundcolor yellow
Write-Host "This could take a few minutes" -ForegroundColor Yellow
$ssa = get-spenterprisesearchserviceapplication
$ssa.pause()
}
elseif($searchappresult -eq 2)
{
Write-Host "Continuing without pausing the Search Service Application"
}
else
{
Write-Host "Run the script again and choose option 1 or 2" -ForegroundColor Red
Write-Host "Exiting Script" -ForegroundColor Red
Return
}
}
Write-Host "Stopping Search Services if they are running" -foregroundcolor yellow
if($srv4.status -eq "Running")
{
$srch4srvctr = 2
set-service -Name "OSearch15" -startuptype Disabled
$srv4.stop()
}
if($srv5.status -eq "Running")
{
$srch5srvctr = 2
Set-service "SPSearchHostController" -startuptype Disabled
$srv5.stop()
}
do
{
$srv6 = get-service "SPSearchHostController"
if($srv6.status -eq "Stopped")
{
$yes = 1
}
Start-Sleep -seconds 10
}
until ($yes -eq 1)
Write-Host "Search Services are stopped" -foregroundcolor Green
Write-Host
#######################
##Stop Other Services##
#######################
Set-Service -Name "IISADMIN" -startuptype Disabled
Set-Service -Name "SPTimerV4" -startuptype Disabled
Write-Host "Gracefully stopping IIS W3WP Processes" -foregroundcolor yellow
Write-Host
iisreset -stop -noforce
Write-Host "Stopping Services" -foregroundcolor yellow
Write-Host
$srv2 = get-service "SPTimerV4"
if($srv2.status -eq "Running")
{$srv2.stop()}
Write-Host "Services are Stopped" -ForegroundColor Green
Write-Host
Write-Host
##################
##Start patching##
##################
Write-Host "Patching now keep this PowerShell window open" -ForegroundColor Magenta
Write-Host
$starttime = Get-Date
$filename = $patchfile.basename
Start-Process $filename
Start-Sleep -seconds 20
$proc = get-process $filename
$proc.WaitForExit()
$finishtime = get-date
Write-Host
Write-Host "Patch installation complete" -foregroundcolor green
Write-Host
##################
##Start Services##
##################
Write-Host "Starting Services Backup" -foregroundcolor yellow
Set-Service -Name "SPTimerV4" -startuptype Automatic
Set-Service -Name "IISADMIN" -startuptype Automatic
##Grabbing local server and starting services##
$servername = hostname
$server = get-spserver $servername
$srv2 = get-service "SPTimerV4"
$srv2.start()
$srv3 = get-service "IISADMIN"
$srv3.start()
$srv4 = get-service "OSearch15"
$srv5 = get-service "SPSearchHostController"
###Ensuring Search Services were stopped by script before Starting"
if($srch4srvctr -eq 2)
{
set-service -Name "OSearch15" -startuptype Automatic
$srv4.start()
}
if($srch5srvctr -eq 2)
{
Set-service "SPSearchHostController" -startuptype Automatic
$srv5.start()
}
###Resuming Search Service Application if paused###
if($srchctr -eq 2)
{
Write-Host "Resuming the Search Service Application" -foregroundcolor yellow
$ssa = get-spenterprisesearchserviceapplication
$ssa.resume()
}
Write-Host "Services are Started" -foregroundcolor green
Write-Host
Write-Host
Write-Host "Script Duration" -foregroundcolor yellow
Write-Host "Started: " $starttime -foregroundcolor yellow
Write-Host "Finished: " $finishtime -foregroundcolor yellow
Write-Host "Script Complete"
Thanks,
Russ Maxwell, MSFT
Fantastic!!!
Well this saved me a lot of time. Great blog Russ!
Could this same type of script be used for SharePoint 2010?
Great work. Begs the question why can't the cu update do this?
Worked like a champ first time, thanks Russ!
*********output******************
Patch installation complete
Starting Services Backup
Starting Distributed Cache Servic
Services are Started
Script Duration
Started: 4/29/2013 10:08:47 PM
Finished: 4/29/2013 10:21:40 PM
Fantastic, thanks.
Is it possible for MS to put out a CU for SharePoint that just installs without issues? It's amazing that this hasn't been integrated into the CU. It's almost as if MS approach everything in a really slack, ill thought out manner?
Hi Russ,
My results are somewhat strange, I am getting almost 10 Seconds across my one WFE and two APP Server farm. Which I do see the CU install popup window. Script closes gracefully, but there is no KB# listed under CA>Upgrade & Migration>Manage Patch Status. Any advise? Thanks for finding this issue and saving us the time…
Below is my script run:
Stopping Search Services if they are running
Search Services are stopped
Gracefully stopping IIS W3WP Processes
Attempting stop…
Internet services successfully stopped
Stopping Services
Gracefully stopping Distributed Cache, this could take a few minutes
Distributed Cache disabled
Services are Stopped
Patching now keep this PowerShell window open
Patch installation complete
Starting Services Backup
Starting Distributed Cache Service
Services are Started
Script Duration
Started: 5/5/2013 12:58:53 AM
Finished: 5/5/2013 12:59:26 AM
That's strange Rajesh. I ensure your running powershell as an Administrator. If that doesn't work, do you have the same problem running the file manually assuming it's in the same location where the script is pointing? I'm thinking maybe your experiencing some errors during setup and may need to go check the setup log.
Russ….we are getting issue while installing the CU …
While the installation and upgrade of the SharePoint farm completed, the User Profile service broke. At this stage I have not been able to successfully get the User profile service recreated. The issue is that when the User Profile Service restarts it recreates duplicate copies of the FIM certificates.
Do you have any idea .?
I noticed the same issue with updates installed on a SharePoint 2013 server that's already configured vs one that's a fresh install. Thanks so much for the script!
I'd be surprised if my script had anything to do with problems with the UPA since it doesn't touch any of those services. Did you get around the issue? I'm curious what errors your getting in ULS..
Wow, I should have seen this some days ago… I used _8 hours_ to be able to install the SharePoint Server March Cumulative Update. The first tries I tried to install the update it failed, but after 2-3 tries it went through.
And then before leaving my job that day I started the installation of the April Cumulative Update, and it was finished the morning after when I got back to work. Pjuh.
You have to share this post out there! Before anyone else uses 5 hours to install the update!
Hi and thanks for this helpful post. I have a problem and hope you can help me. After Installing March CU for SP 2013 (I don't know weather it is successful) I can not loggon into SharePoint anymore. I have plenty of errors on the log among others
Token Cache: Failed to get token from distributed cache for '0).w|s-1-5-21-1844237615-1897051121-839522115-12500'.(This is expected during the process warm up or if data cache Initialization is getting done by some other thread).
Hi Max,
When I run the above script it gives me successfully patch, however I don't see it installed on the program features under installed update. Any pointers what is going wrong?
I should think that stopping the similar services for SP Server 2010 will also speed up the process? The last CU I applied took over 5 hours to apply, per server. if I can stop those services and get this down to less than 1 hour that would be awesome. Can you confirm that stopping IIS, Search, and the timer servies will not cause any issies for 2010?
Thanks for your time and efforts on this!
Hi
Do i need to run the wizard after the script?
Don't use this method if you want to keep your appfabric distributed cache working!!
This is the reason why some of your User Profile Sync. Services won't start anymore 😉
I commented out the AppFabric service (that is not the proper way to stop that service). At any rate, the installation took about 30 minutes. So, perhaps you can revamp your script to not touch AppFabric?
Hope this helps
Yes, you always need to run the config wizard after installing a SharePoint update
Hi,
I've read that it is best practice to stop SPTimerV4 first, before stopping search componets:
blogs.technet.com/…/how-to-install-update-packages-on-a-sharepoint-farm-where-search-component-and-high-availability-search-topologies-are-enabled.aspx
And my installation take long, even with script. i see following process taking up to 50-60% CPU:
.Net Runtime Optimization Service
Is this normal?
My results are as follows…..
is that possible it Update would finish in few seconds :s
I was doing JUNE CU….
=====================================================
Choose 1 to Pause Search Service Application
Choose 2 to leave Search Service Application running
Press 1 or 2 and hit enter: 1
Pausing the Search Service Application
This could take a few minutes
True
Stopping Search Services if they are running
Search Services are stopped
Gracefully stopping IIS W3WP Processes
Attempting stop…
Internet services successfully stopped
Stopping Services
Gracefully stopping Distributed Cache, this could take a few minutes
Distributed Cache disabled
Services are Stopped
Patching now keep this PowerShell window open
Patch installation complete
Starting Services Backup
Starting Distributed Cache Service
Resuming the Search Service Application
True
Services are Started
Script Duration
Started: 8/15/2013 3:25:07 PM
Finished: 8/15/2013 3:25:36 PM
Script Complete
===============================================
Hi,
Thanks for the great script, I just used it to update my development environment.
The directory path to my patch files happened to contain spaces and I received an error on the following line
. .$filename /passive
I simply replaced it with the following
[System.Diagnostics.Process]::Start(".$filename", "/passive")
and the script worked perfectly.
Thanks again.
Thanks Wes and Ryan for providing feedback. After testing the script with latest patches I confirm your findings. I have removed all aspects of appfabric from the script so it will now take 30 minutes per server. I also updated the following start up logic.
$filename = $patchfile.basename
$arg = "/passive"
Start-Process $filename $arg
Thanks again,
Russmax
Many thanks for providing the script. Appreciate it if you would version it and add a version specific notes section.
e.g.
# CurrentVersion = 1.1
#
# Version 1.0 – initial release
# Version 1.1 – Removed app fabric and tidied up start process
etc.
🙂
Hi Russ,
When we extract the SP Aug 2013 CU it also contians a cab file "ubersrv_1.cab", do we need to put this as well in the scripts folder?
Thanks in advance!
Bhavik
Hi,
Do you by any chance have a version of this script for SharePoint 2010?
If not is OSearch15 the only value I would have to chance to OSearch14 to adopt it for SharePoint 2010 CU roll out?
Thanks,
Alex.
Bhavik, yes you do and that's a good observation. I noticed the CU's that came later also have a cab associated so you'll need to leave that or the scriptcu will error out.
Alex, I haven't thought about writing one for SP2010. Are the patch times poor for you in 2010?
Nice post, Really it helps a lot and saved time.
I reffered this post for SP 2013 August CU, it works fine, only I had to include Cab file with setup.exe.
Thanks,
Sushil
Rus,
The bulk of your recommendation is similar to what's documented here: blogs.technet.com/…/how-to-install-update-packages-on-a-sharepoint-farm-where-search-component-and-high-availability-search-topologies-are-enabled.aspx
The difference being that you're also stopping the IIS service. I wonder whether this is supported for the binary portion of the install. The reason I wonder is that if you install a 2013 CU on (for example) a 3-server farm (WFE, APP, Search), the binary portion of the install takes a different amount of time depending on the number of deployed services. The WFE will complete first (by a lot), then search, and finally the APP server. I have verified this on a number of farms. So it is clear to me that the binary installation differs depending on deployed services. I don't know well enough the mechanism behind this, and hence my question about stopping the IIS service.
Any thoughts on this?
Thanks!
Hey Tommy,
I wasn't aware of that link but good to know others from Microsoft our documenting this behavior. For your question, stopping IIS services is a very common activity. We recycle application pools nightly by default. Plus, I wouldn't want IIS listening for inbound traffic while I'm patching. When the script disables IIS services, it's doing it through services.msc on the box. It's not doing any kind of deprovisioning of iis sites which would happen if you manually stop the Web App service in CA -> Services on Server.
Thanks,
Russ
I tried it with the October CU and it gave me an error stating – can not find a process with the name ubersrv2013-kb2825647-fullfile-x64-glb.exe
Hi Russ,
Thanks for sharing the script.
Can this script be used to install security patches as well or is it only for Cumilative Updates?
I had problems when my environment used FQDN because the server name in line 163 is missing the domain name. I modified to fix:
##Grabbing local server and starting services##
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$servername = hostname + "." + $domain
$server = get-spserver $servername
-Costoda
I need to install PU + August CU. Do I have to run psconfig after install PU, then install the CU? or I can install PU+CU, then psconfig? thanks.
Hi Russ,
Thank you for putting this together. Unfortunately I went through the pain of 5 hours of patching each server first time around (before coming across this :-)).
Now that I'm trying to executive this script I run into the following error message. Any suggestion what that might be? This is coming from line 144. I do have only "ubersrv2013-kb2825647-fullfile-x64-glb.exe" and your script on the same folder in the server.
Appreciate any feedback as always!
get-process : Cannot find a process with the name "ubersrv2013-kb2825647-fullfile-x64-glb". Verify the process name and call the cmdlet again.
many thanks!
Hi Russ,
Thanks yo so much!
Thanks!
I thought my SharePoint 2013 Cummulative update had hanged after running for about one hour. I then cancelled it and ran again with this script. Result: Installation done in 10minutes. Thanks!
Can this script be used to install SP1 of SharePoint 2013?
@Dennis – script looks like it works with any EXE file – going to try it with SP1 on a test farm tomorrow I think – will post results as installing SharePoint 2013 SP1 on a fresh install of SharePoint 2013 and Windows Server 2012 takes longer than 5 hours.
Excellent post… Thanks Maxwell for such use full post…
Has anyone tried this script with Service Pack 1 for SharePoint 2013 yet? Does the process behave any differently in this case or should it run just the same?
Thanks -BJ
Just tried with SP1 and crashed my User Profile Service Application and Search Service. Did a restore and upgrade again without the script and then it worked. However took 4 hours.. 🙁 Anyone else have any experiense with this?
I just used this script to upgrade to SP1 from RTM. Worked perfect and took about 40 minutes. Thank you!
Hi, it looks like you never acted to Ragesoft's remark that you need to stop SPTimerV4 before stopping the Search components. As that other Microsoft blog points out:
"The reason why you need to stop the SPTimerV4 service first is because the SPTimerV4 service monitors the SPSearchHostController service. The SPTimerV4 service will start the SPSearchHostController service it if it finds that the SPSearchHostController is stopped. Therefore, if the SPTimerV4 service is running after you stop the SPSearchHostController service, the SPTimerV4 service might start the SPSearchHostController without you noticing it."
I think you need to switch the order a little in your script, so the Timer Service is stopped first, right?
Why use $ssa.pause() instead of Suspend-SPEnterpriseSearchServiceApplication?
How should this be coordinated with a content db detach/attach? Attach content dbs before or after starting services?
I ran the script to install SP1 for SharePoint 2013 on a dev environment that is runing Windows Server 2012. It ran like a champ but I was wondering if anyone has run this on a server runnining Windows Server 2008 R2.
Let me look at the latest suggestions and I'll respond soon…
Thanks,
Russ
I just used this script for the March PU and it completed in 26 mins without a hitch.
There were some dreaded red Powershell lines at the start before the Service Pause option appeared. These appeared to be lines of the script like // Author: Russ Maxwell and othe words and characters being read as 'terms' by Powershell.
Excellent work. Thank you.
The AppFabric sections should be re-added as you do a reboot. Graceful shutdown is totally supported way of stopping the service (as opposed to stopping the service in Services on Server)
Hello Friend!
I am trying to apply SP1 to my sharepoint server 2013 environment. I tried this script but it is not working..
please help.
Running the binaries..does that need to be sequential or is that ok to simultaneously run the script on all servers in the farm? Then, run the Configuration Wizard on the boxes running Central Admin first and one at a time? Thanks
Hi Rush, Thanks for this wonderful article!! I was wondering if we could explore the similar way for SharePoint 2010 environment as well? I read the entire thread however looks we didnt see a conclusion on approach for 2010?
Look forward to hear from you!!
best wishes!!
Shekhar
Dear Russ,
Please advise if your script works for Service Pack 1 (i.e. reduce the installation time) re-released in May 2014 blogs.technet.com/…/sp1-for-sharepoint-2013-has-been-rereleased.aspx
Thanks & Regards,
Anthony
Thank you so much for this script! I am putting it in a folder named "Quiesce 2013". 🙂
I have a multi-server environment and I'm wondering about the sequence of applying patches to servers. I see you said it could be run simultaneously…is that the best approach? I have one WFE and one app/CA server in dev. Two WFE's, an app/CA server and a dedicated Search-only server in Prod. For the March/April 2013 CU/PU i followed Kirk Stark's guide for Search environments and it worked well. blogs.technet.com/…/how-to-install-update-packages-on-a-sharepoint-farm-where-search-component-and-high-availability-search-topologies-are-enabled.aspx Thanks again and I look forward to any comments you might have about sequencing.
Tip of my beer to you.
Works also for SharePoint 2013 SP1. Thanks an lot russmax !
Thanks alot Max.Nice post
Hi! A great script! What I want to add is loading of SharePoint PSSnapin: just add this in the script: asnp *share* Otherwise you cannot use SharePoint-related CMDlets.
Has anyone run the script with the July 2014 CU?
I second Chaz…also what about if the CU has the Application file as well as the 2 CAB files. Can you simply drop all 3 files in the same folder with your script?
Used before only on a CU that had a single file and worked great!
Has any one used the script for July-cu 2014 for Sp-2013 ,I tried, No errors but with in a minute its showing "patch installation complete" but its not updated really.It has 2 cab files,so its the same script or need any modifications?
I've used this to install the July 2014 update and it didn't have any problems. The additional cab files get picked up with the patch install. The script ignores them.
Brian – Thanks for the reply. I just applied Sept. CU and worked without any problems.
Can this be executed on other servers simultaneously?
Why after installation of July .2014 CU it shows the version 15.0.4631.1000 or is this version correct. I had downloaded the CU for SP2013 server edition … as I assume SP foundation is automatically in cluded and one need not have to install this first and then server.
Great post. Wonder if order of stopping and starting services will make any difference. or make process any better as described here :
blogs.technet.com/…/how-to-install-update-packages-on-a-sharepoint-farm-where-search-component-and-high-availability-search-topologies-are-enabled.aspx
Note: The reason why you need to stop the SPTimerV4 service first is because the SPTimerV4 service monitors the SPSearchHostController service. The SPTimerV4 service will start the SPSearchHostController service it if it finds that the SPSearchHostController is stopped. c. Restart the Windows Services in the following order:
Thanks for sharing.
Fabulous post….
I used this script successfully in a SharePoint 2010 environment. Certainly saves some time with installing the binaries. Remember to unzip your CU's first, otherwise the script will only unzip the files for you (completes quickly), but won't run the CU. You'll need to modify the script to replace OSearch15 with OSearch14, and also remove any code related to "SPSearchHostController" ($srv5 & $srv6).
Sharepoint surely sucks and this script is a great one. Can I run this after I have stupidly started the upgrade process manually w/o realizing how much time its going to take ? it seems SP's SP1 takes longer than SP1 of the OS itself … 😉
We will be installing a bunch of CUs on our SharePoint servers, I was wondering what approach do i need to follow in order to use this script.
– copy sp1 installable — run the script
– copy May 14 CU – run the script
—
let me know if my understanding is correct?
Gongrats!!
It saves a lot of time 🙂
Russ,
We would like to use this script on SharePoint 2013 SP1 on WIndows Server 2008 R2 SP1. Will it work on that OS.
Thanks.
Hello.
Can we use this script to install security updates also?
Cheers for the script!
Ran it on Server 2008 R2, SharePoint 2013 SP1 upgrading to Cumulative Update Sepember 2014 without any problems. (30mins installation on a underspec'ed Virtual server)
One thing that I was in doubt about is the requirement to run the psconfig afterwards. I do not see it included in the script nor any mention of this.
So I presume it's required to run after the script has completed?
Thank you much for writing this post! You saved me a bunch of time and taht is a tremendous gift. You are the man!
Hi There!
I found this Blog wile searching for reasons why my Sharepoint Update took 26 Hours 🙁
What i miss in this script ist the PSCONFIG. The long part in an Sharepoint Update Process is the Upgrade of the Content_Databases. This happens wile running PSCONFIG.
Did nobody run PSCONFIG or upgraded the Databases after the CU-Installation? How long did it take??
I'm going to assume that the PSConfig isn't in the script because you need to install the binaries across the farm servers before attempting to psconfig any of the machines.
Hi Steve and Alex
Yes you will still need to run PSCONFIG after the script.
Russ, Awesome Script! Saved me many many hours now.
have anyone try the script with security updates, someone already asked twice,
Presuming the script and patch are copied to a remote server, can the script be run remotely using powershell – if so what is correct command ?
Thanks for all hard work !
Thank you. It was so fast. Super. 🙂
I am still getting a prompt to install the patch even though it should be installing in /passive mode ? This is preventing remote execution. Any ideas please ?
Answer was the file was from untrusted source. Go into properties of file and unblock – now executes in passive mode without any prompts.
I am stuck in Pausing Search Service Application even though when I checked the CA>Search Service Application, it is a,s=ready paused. It says this could take few minutes but its more than an hour an still stucks in the same place..Any idea?
I am stuck in the first step-Pausing Search Service Application- This may take few minutes. I checked the CA>Search Service Application and it is already paused but the script keeps showing same message and its been more than an hour. I cancelled and ran it again and still getting same message and doesnt move to next step.Any ideas?
@Ben Is the process running ? Is it doing anything (CPU/Memory) ? Go to location for ULS logs and check the upgrade log. If you see my post above, I found the file was open waiting for user input as it was set to blocked. You can use unblock-file to unblock it, or add it to this script.
Hope this is useful
any idea why the search service application does not resume after the script is run? I thought the script will resume SSA. Another question- is the process same for the servers running the search component? Do we need to stop the Timer Service, Host Controller Search Service and Osearch15 through services for server running the search component?
All of my cumulative updates have several .exe files. Is it possible to run them all at once?
Thanks Russ,
I ran the script and all appears to have worked but a few errors during the patching, please see output.
Any idea why there were errors during the patch sequence.
Pausing the Search Service Application
This could take a few minutes
get-spenterprisesearchserviceapplication : The term 'get-spenterprisesearchserviceapplication' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At D:SharepointCUMay2015CUInstall.ps1:62 char:16
+ $ssa = get-spenterprisesearchserviceapplication
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-spenterprisesearchserviceapplication:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You cannot call a method on a null-valued expression.
At D:SharepointCUMay2015CUInstall.ps1:63 char:9
+ $ssa.pause()
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Stopping Search Services if they are running
Search Services are stopped
Gracefully stopping IIS W3WP Processes
Attempting stop…
Internet services successfully stopped
Stopping Services
Services are Stopped
Patching now keep this PowerShell window open
Patch installation complete
Starting Services Backup
get-spserver : The term 'get-spserver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At D:SharepointCUMay2015CUInstall.ps1:163 char:11
+ $server = get-spserver $servername
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-spserver:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Resuming the Search Service Application
get-spenterprisesearchserviceapplication : The term 'get-spenterprisesearchserviceapplication' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At D:SharepointCUMay2015CUInstall.ps1:188 char:12
+ $ssa = get-spenterprisesearchserviceapplication
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-spenterprisesearchserviceapplication:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You cannot call a method on a null-valued expression.
At D:SharepointCUMay2015CUInstall.ps1:189 char:5
+ $ssa.resume()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Services are Started
Script Duration
Started: 6/17/2015 3:06:45 PM
Finished: 6/17/2015 3:19:43 PM
Script Complete
PSCONFIG, What I did!
I added the below lines to deal with PSCONFG running as soon as the patch is applied. It has a prompt where you can say no and it will not run it, in the case you a have a multiple server environment.
I put this function at the top:
#Region PSConfig
Function Run-PSConfig
{
Set-Alias PSCONFIG "${env:commonprogramfiles}Microsoft SharedWeb Server Extensions15BINPSCONFIG.EXE"
Start-Process -FilePath PSCONFIG -ArgumentList "-cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures" -NoNewWindow -Wait
}
$PSConfig = "$env:CommonProgramFilesMicrosoft SharedWeb Server Extensions$env:spVerBINpsconfig.exe"
#EndRegion
Added this right after:
###########################
##Ensure Patch is Present##
###########################
$patchfile = Get-ChildItem | Where-Object{$_.Extension -eq ".exe"}
if($patchfile -eq $null)
{
Write-Host "Unable to retrieve the file. Exiting Script" -ForegroundColor Red
Return
}
###########################
##Should we run PSConfig ##
###########################
Write-Host "Should PSConfig be run at the end of the process?" -ForegroundColor Cyan
Write-Host "Choose Y to have PSConfig run instantly after the updates have been applied" -ForegroundColor Cyan
$spconfigResult = Read-Host "Press Y or N and hit enter"
Added this part after:
Write-Host "Script Complete"
if($spconfigResult -eq "Y")
{
Write-Host
Write-Host
$starttime = Get-Date
Write-Host "Running PSConfig.exe"
Run-PSConfig
Write-Host
Write-Host
$finishtime = Get-Date
Write-Host "PSConfig Duration" -ForegroundColor Yellow
Write-Host "Started: " $starttime -ForegroundColor Yellow
Write-Host "Finished: " $finishtime -ForegroundColor Yellow
}
I hope this helps
Oops!
You don't need the below line.
$PSConfig = "$env:CommonProgramFilesMicrosoft SharedWeb Server Extensions$env:spVerBINpsconfig.exe"
This may be obvious to a more experience SP admin but you need to download both CAB files as well as the EXE to run this script. It will run without them just finish successfully in minutes and do nothing. With the cab files it actually works.
Still the worst product MS has ever created but your script narrows that margin a little lol thanks!
Article for SharePoint Farm patching with it's DR (Hot Standby) with SQL Server AlwaysOn: The current version on my SharePoint 2013 + Project Server 2013 enterprise is RTM and I want to update this to 2014 September CU for both SharePoint and Project Server. While there are documentation available on the SharePoint Farm upgrade which also included the DR farm (in my case hot stand by) for the SQL server log shipping mechanism blogs.msdn.com/…/patching-sharep…, I could not find any reference or article on SharePoint patching on a SQL Server 2012 AlwaysOn setup with Asynchronous commit. Although there is an article which says AlwaysOn Asynchronous replication is supported by SharePoint 2013, but in terms of SharePoint patching and what should be the approach nothing that I can find of. If you are aware of any article, preferably Microsoft article or any blog post giving information on the above, please let me know. Thanks in advance, Sushanta
Hi, I wonder if any of the stopped sevices are needed by the upgrade process. Doesn't it use web service calls, or the Server Object Model, or SharePoint cmdlets that put things in SharePoint job queue? It's just plain binary replacement and DB modifications?
Hi Russ, great script, but I think I am doing something wrong.
When I press 1 to pause Search, it just sits at pausing, this make take a few minutes. Looking at the service in Central Admin, it shows Paused:External Request, but the script never seems to continue. It's like there's no logic in the scipr to check the search application is now paused.
What have I done wrong?
Mark
Wow, why didn't I find this earlier? This script was a lifesaver! Thank you so much
Hi Russ, i have used your script in combination with the September 2015 CU and the script runs fine. The problem is that when i run the SP Config wizard now it complains and tells me IIS is not installed.
IIS is installed, its started, the World Wide web services are started. When i look into the Services, i don't see any SharePoint service anymore???
SharePoint Administration, Search Host controller, Server Search 15, Timer Service, Tracing service , User Code Host and vSS Writer are completely missing.
Rebooted the box a couple of times and had a look into MSCONFIG to see which services are running and what i do see is that for example the SharePoint Admin service is stopped but i cannot start it.
Any idea what could be wrong? I tried to run the script once more but it tells me there is no need as no additional updates can be applied. CA is not showing any errors, but of course i need to run the wizard.???
Hope someone has an idea
Jan
Thanks so much for your work
Hi Russ,
I am trying to install Aug 2015 CU.
Initially it was stuck after pausing crawl and I waited and waited for hours and it did not come back.
Second I cancelled the script.
Restart the box to make it work normally and it worked.
Then I stopped services one by one as script is doing
Finally install the Aug 2015 package and its been 2 hours and pkg is still extracting it.
It is 5:30pm here and I am leaving it and hoping that by tomorrow morning; it will be installed.
So your script could not save my time. Please advise.
One stupid question.
Is it required to run SharePoint Product Configuration Wizard after CU installation?
Regards
@Jan Gremmen, the script does not properly start the "IIS Admin Service" after the September 2015 CU and makes the "Start" button in "Services" greyed out.
To start it after the script has run, go to "Services", right click "IIS Admin Service", set startup type to be "Automatic". You should now be able to start the service (right click and click Start) and run PSConfig.
@UNKNOWN yes you need to run the configuration wizard in order to actually apply the upgrade to the databases. If you look in Central Administration under Manage servers in this farm you'll see "Upgrade required" for your SharePoint server(s), and there might even be a link with instructions.
The script fails on the line:
Start-Process $filename
With error:
"Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported."
Perhaps some difference in PowerShell versions?
Same Problem here starting with
Start-Process : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported.
At C:installCU_2015DecSharePoint_Patching.ps1:141 char:15
and continous with
get-process : Cannot find a process with the name "xwizard". Verify the process name and call the cmdlet again.
At C:installCU_2015DecSharePoint_Patching.ps1:144 char:10
I think I just found my error. The Get-ChildItem was executed was executed in system32 and not in Scripting Folder.
Thanks for this… Setting up a new SharePoint instance and patching it, I had a patch that was running for two hours and didn't seem to be doing anything. After cancelling and wrapping it in this script, it finished in mere minutes.
Very helpful- Thanks!
Just a question on patching multiple servers – what's the sequence? Would you manually pause the SSA on the first search server to be patched, patch all search servers, then manually start the SSA? Or other suggestions?
Very interesting and helpful, thank you for sharing the information!
HI,
In the script you are disabling IISAdmin Service and then You do the IISreset stop -noforce.
But IISReset is not only for IISAdmin Service. It includes 4 more. Hence, for patch installation is it enough to disable and stop IISAdmin Service only?
Or should all services running under IISREset be stopped?
That is question which i cannot find answer for.
In my opinion disabling and stopping IISAdmin Service should be enough
@TZ How did you correct this "I think I just found my error. The Get-ChildItem was executed was executed in system32 and not in Scripting Folder."
@TZ and anyone else having trouble here.
adding the below "cd C:scripts" solved my problem and allowed the remaining script and patch to run successfully.
cd C:scripts
$patchfile = Get-ChildItem | where{$_.Extension -eq ".exe"}
if($patchfile -eq $null)
Just an update from my testing. The script installed the CU successfully. Post installation, we should run the PS configuration wizard to
• SharePoint Configuration Wizard updates the database schema to the latest version
But, unfortunately the wizard failed in step-9 and I re-run the script but still the same. I don't find anything weird in the logs. Anybody had the similar experience. Please provide your comments.
Dave Crosby,
In order to update SP on multiple Search servers, you could follow the procedure on the following article:
blogs.technet.microsoft.com/…/how-to-install-update-packages-on-a-sharepoint-farm-where-search-component-and-high-availability-search-topologies-are-enabled
Cheers
Hello Guys,
I wanna let you know, we got a configuration wizard error message after installation. Like above comment. Please shed a light.
cheers,
There are so many reasons that can happen – you have to get the error from the Upgrade-error.log file and troubleshoot that. If you don't see the Udate-error.log file in the log folder, then run the PSCONFIG from the command line. Sometimes the GUI doesn't generate the log. If still no log, check your diagnostic logging levels. If you get an error running either PSCONFIG or PSCONFIGUI – ALWAYS try running it again, and again. If you're upgrading multiple servers in the farm run it on all servers, then again on the one that failed.
I've seen a few folks ask this but no response – Can you execute this script on multiple servers at the same time, then run the PSCONFIG on each server?
After using my own script for a while I found this one to be more helpful. The one thing that I was surprised by was that a few CUs have failed due to the fact that IIS could not be started because the script disabled the service. I'm not familiar enough with the CUs process but it seems to try to start the services before the script re-enables them.
This script stops and disables the OSearch15 service and later re-enables it and starts it again.
On every SharePoint 2013 farm I have looked at, the default state of the OSearch15 service is either Disabled (if it's a WFE) or Manual (if it's a search server).
This script sets the OSearch15 service to Automatic rather than Manual when it finishes, and therefore leaves the server in a fundamentally different state than when it started. This seems wrong to me. I'm not suggesting that it is a huge deal, but I am not comfortable with it making this change. It should set the service start-up type back to the way it was originally.
@Chanty
I had the same question. The answer is it depends on how you want the Search Service Application to be handled. If you have multiple servers running the Search Service (which runs on individual servers) the script prompts to start and stop the Search Service Application (which applies to the whole farm). That can be confusing. I stop the SSA on the first farm I patch, and then start it again on the last farm I patch.
I wrote my own variation of the script that separates the process out so I can do the 3 steps manually (stop, install, start) – that's less confusing for me with a multi-server farm and gives me greater control. I also added a feature to display the current state of all the services, and saves it to disk so you can reboot without losing the original state of the services. Then running it in display mode compares the current state with the original state.
Regards!
@David Crosby
Thanks to Russ and all others for sharing the information.
We intended to install the latest CU in our UAT environment and we have multiple servers in the farm and I was thinking the same, how to use this script in multiple servers which one to start first?
Could you please share your script and which server to start with.
Regards!
@Mahdi
I patch in this order: 1) Central Admin server, 2) Search Servers, 3) Other Application Servers, 4) WFEs.
If you have redundant search servers, spit them into groups according to where the indexes live so there is always one available. The principal for choosing the order is, start with the critical servers first and work down to the least important.
You can find my SharePoint Services Manager script in the gallery: gallery.technet.microsoft.com/…/SharePoint-Manager-6a6e14c8
Hope it helps!
Thank you. I went through the "normal" installation once for SP 1 SharePoint 2013… it took 3.5 hours. found this script, it took less than 30 minutes.. just, wow… but thank you very much… very useful and easy to understand.
This worked then, This works now. Cant just feel better to come over here and say thanks to you, Again !!
17 minutes and it is done.
Awesome. !!!!
@Krish – 17 minutes? Really? does that include running PSCONFIG, or just the patch installation? I'm surprised it would finish that fast – but if so, AWESOME!
Cheers!
45 minutes for us which obviously doesn't include PSCONFIG time. Thanks for the resource and shame on me for not checking this out earlier.
Hello,
We have got the below error when runnning the PS config wizard though the script is successful. Please fine below…Help us..
Failed to upgrade SharePoint Products.
An exception of type System.DirectoryServices.DirectoryServicesCOMException was
thrown. Additional exception information: The service cannot be started, either
because it is disabled or because it has no enabled devices associated with it.
Total number of configuration settings run: 3
Total number of successful configuration settings: 2
Total number of unsuccessful configuration settings: 1
Successfully stopped the configuration of SharePoint Products.
Configuration of SharePoint Products failed. Configuration must be performed be
fore you use SharePoint Products. For further details, see the diagnostic log l
ocated at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\1
5\LOGS\PSCDiagnostics_3_28_2016_6_42_10_771_632310512.log and the application ev
ent log.
I finally got around to trying this today. 30 minutes to install the April 2016 CU on my 4 server farm at home. At work, it took 3 1/2 hours.
Thanks a lot Russ: from 6 hours to 10 minutes! 🙂