It's a high risk not to patch but a guaranteed risk to apply the patches.
Last year I had a difficult experience when I patched a semilarge(7 members) farm for the first time with Cumulative Updates.
This had 5 webapplications and +200 databases. And it took some time. Like 30 hours, most of the time being lost when running psconfig on each host.
Supposedly, sharepoint should only upgrade the databases on the first member run, but something still takes a lot of time, even its only to check if upgrade is required.
So a more effective method was needed.
I looked into the impressive SPPatchify-project but found the results to be too inconsistent. Sometimes the script ran through it all and said everything was green, when actually two servers had failed psconfigs and a lot of other issues giving half-finished state.
So I deviced my own hybrid method using the best parts of the sppatchify-idea and russmax exe-installationscript.
The method took the installationwindow down to 4 hours in total, where only 2 hours was complete downtime.
Its a bit more manual than others, but therefore also gives more control.
The steps
Preperations
- Take whole farm offline and take snapshots, or use regular backups. Whichever method you trust most.
- Backup All databases
- Stop all sharepointrelated-services
- For AppServers 1. App-Prepatching
- For Frontends 1. WFE-PrePatching
- Run exe on all members
- Start all services
- For AppServers 2. App-PostPatching
- For frontends 2. WFE-PostPatching
- Export all databasinformation to file.
- ExportAllDbs.ps1
- Dismount all databases (after making sure you have all correct info on file from previousStep) This will take everything offline.
- DismountAllDbs.ps1
- Run psconfig on all members starting with AppServers
- RunPSConfig.ps1 on each member
- Mount all databases
- MountAllDbs.ps1 - Update the filename to your exported databases
- Upgrade databases in parallel. While each db is upgrading website on it will be unavailable. If you're sql supports it you can mitigate this using -usesnapshot How many concurrent jobs is depending on hardware. I found the sweetspot to be 4 concurrent jobs, after that it started taking longer time that running them in sequence. But this might vary.
- UpgradeDatabasesFaster.ps1
- Check on warnings in Health Analyzer, make repairs if needed.
- Make sure User Profile Synchronizer service is running (if your using FIM-sync)
Below all relevant scripts. Use at your own risk.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue | |
$starttime = Get-Date | |
######################## | |
##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 | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$starttime = Get-Date | |
Add-PSSnapin microsoft.sharepoint.powershell | |
####################### | |
##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()} | |
#stop distcache | |
write-host -foregroundcolor yellow "Stopping Distributed Cache Service gracefully..." | |
Stop-SPDistributedCacheServiceInstance -graceful | |
write-host -foregroundcolor red "Distributed Cache is stopped." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
write-host -foregroundcolor Yellow "Status of Distributed Cache Services = "$instance.status | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.Powershell | |
$starttime = Get-Date | |
################## | |
##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" | |
###Starting Search Services### | |
set-service -Name "OSearch15" -startuptype Automatic | |
$srv4.start() | |
Set-service "SPSearchHostController" -startuptype Automatic | |
$srv5.start() | |
###Resuming Search Service Application### | |
Write-Host "Resuming the Search Service Application" -foregroundcolor yellow | |
$ssa = get-spenterprisesearchserviceapplication | |
$ssa.resume() | |
#distcache | |
write-host -foregroundcolor green "Starting service .." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
$instance.provision() | |
write-output "Distributed Cache has status: $($instance.status)" | |
Write-Host "Services are Started" -foregroundcolor green | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$starttime = Get-Date | |
################## | |
##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" | |
###Starting Search Services### | |
#set-service -Name "OSearch15" -startuptype Automatic | |
#$srv4.start() | |
#Set-service "SPSearchHostController" -startuptype Automatic | |
#$srv5.start() | |
###Resuming Search Service Application### | |
#Write-Host "Resuming the Search Service Application" -foregroundcolor yellow | |
#$ssa = get-spenterprisesearchserviceapplication | |
#$ssa.resume() | |
write-output "Starting service .." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
$instance.provision() | |
write-output "Distributed Cache has status: $($instance.status)" | |
Write-output "Services are Started" | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$scriptPath = $(split-path -Parent $myinvocation.MyCommand.Definition) | |
$fileName = "Databases_$(get-date -format 'yyMMdd_HHmm')" | |
$object = @() | |
foreach ($db in $alldbs) { | |
$tempObj = [pscustomobject]@{name=$db.name;webapplication=$db.webapplication.url;databaseserver=$db.normalizeddatasource } | |
$object += $tempObj | |
} | |
$object |export-csv -Path "$($scriptPath)\$($fileName).csv" | |
write-output "Exported $($alldbs.count) databases to file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
foreach ($db in $alldbs) { | |
write-output "Dismounting $($db.name)" | |
Dismount-SPContentDatabase $db.name -Confirm:$false | |
} | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$startTime = get-date | |
write-host "script started at $($startTime)" | |
push-location "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\bin" | |
.\psconfig.exe -cmd upgrade -inplace b2b -wait -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install | |
Pop-Location | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).TotalMinutes) minutes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$scriptPath = $(split-path -Parent $myinvocation.MyCommand.Definition) | |
$fileName = "Databases_170530_1301.csv" | |
$collection = import-csv -path "$($scriptPath)\$($fileName)" | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
foreach ($db in $collection) { | |
try { | |
Mount-SPContentDatabase -Name $db.name -WebApplication $db.WebApplication -DatabaseServer $db.databaseserver | |
} | |
catch {write-output "error: $($_.exception)" } | |
} | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalminutes) minutes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#created: 2017-05-30 | |
#lastModified: 2017-05-30 | |
#description: starts powershell jobs to run $numberofConcurrent at the same time | |
add-pssnapin microsoft.sharepoint.powershell | |
$numberofConcurrentJobs = 4 | |
$jobName = "UpgradeDbs" | |
$collection = get-spcontentdatabase |where-object {$_.needsupgrade -eq $true} | |
$counterJobs = 0 | |
if ($collection.count -ne 0 -or $collection -ne $null) { | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
write-output "Found $($collection.count) databases to upgrade" | |
foreach ($item in $collection) { | |
#argone has to be a string value. no objects allowed. | |
$argOne = $item.name | |
start-job -name "$($jobName)_$($argOne)" -ScriptBlock { | |
$internalString = $args[0] | |
#where action happens | |
Add-PSSnapin microsoft.sharepoint.powershell | |
try { | |
Upgrade-SPContentDatabase $internalString -Confirm:$false -erroraction stop | out-null | |
} | |
catch { write-warning "Error: $internalString : $($_.exception)" } | |
} -ArgumentList $argOne | |
$counterJobs++ | |
#check numberof running jobs, wait until new one can be started | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
while ($jobs.count -ge $numberofConcurrentJobs) { | |
write-output "Waiting for jobs.... at count: $($jobs.count) (started $counterJobs so far) " | |
start-sleep 5 | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
} | |
} | |
#wait for all jobs to be completed | |
while ($jobs.count -gt 0) { | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
write-output "Waiting for all jobs to clear... $($jobs.count) left" | |
if ($jobs.count -gt 0) {start-sleep 15} | |
} | |
#get results from all jobs | |
get-job |where-object {$_.name -like "$jobName*"} |receive-job -AutoRemoveJob -wait | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalminutes) minutes ($(($endtime-$starttime).totalseconds) seconds)" | |
} | |
else { write-output "Couldnt find any databases needing upgrade" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue | |
$starttime = Get-Date | |
######################## | |
##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 | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$starttime = Get-Date | |
Add-PSSnapin microsoft.sharepoint.powershell | |
####################### | |
##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()} | |
#stop distcache | |
write-host -foregroundcolor yellow "Stopping Distributed Cache Service gracefully..." | |
Stop-SPDistributedCacheServiceInstance -graceful | |
write-host -foregroundcolor red "Distributed Cache is stopped." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
write-host -foregroundcolor Yellow "Status of Distributed Cache Services = "$instance.status | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.Powershell | |
$starttime = Get-Date | |
################## | |
##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" | |
###Starting Search Services### | |
set-service -Name "OSearch15" -startuptype Automatic | |
$srv4.start() | |
Set-service "SPSearchHostController" -startuptype Automatic | |
$srv5.start() | |
###Resuming Search Service Application### | |
Write-Host "Resuming the Search Service Application" -foregroundcolor yellow | |
$ssa = get-spenterprisesearchserviceapplication | |
$ssa.resume() | |
#distcache | |
write-host -foregroundcolor green "Starting service .." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
$instance.provision() | |
write-output "Distributed Cache has status: $($instance.status)" | |
Write-Host "Services are Started" -foregroundcolor green | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$starttime = Get-Date | |
################## | |
##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" | |
###Starting Search Services### | |
#set-service -Name "OSearch15" -startuptype Automatic | |
#$srv4.start() | |
#Set-service "SPSearchHostController" -startuptype Automatic | |
#$srv5.start() | |
###Resuming Search Service Application### | |
#Write-Host "Resuming the Search Service Application" -foregroundcolor yellow | |
#$ssa = get-spenterprisesearchserviceapplication | |
#$ssa.resume() | |
write-output "Starting service .." | |
$instance = get-spserviceinstance |where-object {$_.typename -eq "Distributed Cache" -and $_.Server.Name -eq $env:computername} | |
$instance.provision() | |
write-output "Distributed Cache has status: $($instance.status)" | |
Write-output "Services are Started" | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" | |
Write-Host "Script Complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$scriptPath = $(split-path -Parent $myinvocation.MyCommand.Definition) | |
$fileName = "Databases_$(get-date -format 'yyMMdd_HHmm')" | |
$object = @() | |
foreach ($db in $alldbs) { | |
$tempObj = [pscustomobject]@{name=$db.name;webapplication=$db.webapplication.url;databaseserver=$db.normalizeddatasource } | |
$object += $tempObj | |
} | |
$object |export-csv -Path "$($scriptPath)\$($fileName).csv" | |
write-output "Exported $($alldbs.count) databases to file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
foreach ($db in $alldbs) { | |
write-output "Dismounting $($db.name)" | |
Dismount-SPContentDatabase $db.name -Confirm:$false | |
} | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalseconds) seconds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$startTime = get-date | |
write-host "script started at $($startTime)" | |
push-location "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\bin" | |
.\psconfig.exe -cmd upgrade -inplace b2b -wait -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install | |
Pop-Location | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).TotalMinutes) minutes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin microsoft.sharepoint.powershell | |
$alldbs = get-spcontentdatabase | |
$scriptPath = $(split-path -Parent $myinvocation.MyCommand.Definition) | |
$fileName = "Databases_170530_1301.csv" | |
$collection = import-csv -path "$($scriptPath)\$($fileName)" | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
foreach ($db in $collection) { | |
try { | |
Mount-SPContentDatabase -Name $db.name -WebApplication $db.WebApplication -DatabaseServer $db.databaseserver | |
} | |
catch {write-output "error: $($_.exception)" } | |
} | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalminutes) minutes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#created: 2017-05-30 | |
#lastModified: 2017-05-30 | |
#description: starts powershell jobs to run $numberofConcurrent at the same time | |
add-pssnapin microsoft.sharepoint.powershell | |
$numberofConcurrentJobs = 4 | |
$jobName = "UpgradeDbs" | |
$collection = get-spcontentdatabase |where-object {$_.needsupgrade -eq $true} | |
$counterJobs = 0 | |
if ($collection.count -ne 0 -or $collection -ne $null) { | |
$startTime = get-date | |
write-host "script started at $($startTime)" | |
write-output "Found $($collection.count) databases to upgrade" | |
foreach ($item in $collection) { | |
#argone has to be a string value. no objects allowed. | |
$argOne = $item.name | |
start-job -name "$($jobName)_$($argOne)" -ScriptBlock { | |
$internalString = $args[0] | |
#where action happens | |
Add-PSSnapin microsoft.sharepoint.powershell | |
try { | |
Upgrade-SPContentDatabase $internalString -Confirm:$false -erroraction stop | out-null | |
} | |
catch { write-warning "Error: $internalString : $($_.exception)" } | |
} -ArgumentList $argOne | |
$counterJobs++ | |
#check numberof running jobs, wait until new one can be started | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
while ($jobs.count -ge $numberofConcurrentJobs) { | |
write-output "Waiting for jobs.... at count: $($jobs.count) (started $counterJobs so far) " | |
start-sleep 5 | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
} | |
} | |
#wait for all jobs to be completed | |
while ($jobs.count -gt 0) { | |
$jobs = get-job |Where-Object {$_.name -like "$jobName*" -and $_.state -like "Running"} | |
write-output "Waiting for all jobs to clear... $($jobs.count) left" | |
if ($jobs.count -gt 0) {start-sleep 15} | |
} | |
#get results from all jobs | |
get-job |where-object {$_.name -like "$jobName*"} |receive-job -AutoRemoveJob -wait | |
$endtime = get-date | |
write-host "Done in $(($endtime-$starttime).totalminutes) minutes ($(($endtime-$starttime).totalseconds) seconds)" | |
} | |
else { write-output "Couldnt find any databases needing upgrade" } |
References:
https://blogs.msdn.microsoft.com/russmax/2013/04/01/why-sharepoint-2013-cumulative-update-takes-5-hours-to-install/ - Russmax excellent script for halting services before running exe. Saving hours
http://www.spjeff.com/2016/05/16/sppatchify-cu-patch-entire-farm-from-one-script/ - SpJeffs
https://blogs.technet.microsoft.com/stefan_gossner/2015/08/20/why-i-prefer-psconfigui-exe-over-psconfig-exe/ - Excellent resource for patching
No comments:
Post a Comment