Wednesday, September 27, 2017

Patching Sharepoint with the homebrew-method

Patchning Sharepoint is not something to taken lightly.
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

  1. Take whole farm offline and take snapshots, or use regular backups. Whichever method you trust most.
  2. Backup All databases
Installation
  1. Stop all sharepointrelated-services
    1.  For AppServers 1. App-Prepatching
    2.  For Frontends  1. WFE-PrePatching
  2. Run exe on all members
  3. Start all services 
    1. For AppServers 2. App-PostPatching
    2. For frontends  2. WFE-PostPatching
  4. Export all databasinformation to file.
    1. ExportAllDbs.ps1
  5. Dismount all databases (after making sure you have all correct info on file from previousStep) This will take everything offline.
    1. DismountAllDbs.ps1
  6. Run psconfig on all members starting with AppServers
    1. RunPSConfig.ps1 on each member 
  7. Mount all databases
    1. MountAllDbs.ps1  - Update the filename to your exported databases
  8. 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. 
    1. UpgradeDatabasesFaster.ps1
  9. Check on warnings in Health Analyzer, make repairs if needed. 
  10. Make sure User Profile Synchronizer service is running (if your using FIM-sync)


Below all relevant scripts. Use at your own risk.



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

Monday, March 20, 2017

Users break dispform

In this particular case a user decided to throw away the main webpart of the dispform.aspx. This caused all kinds of problems since it was a calenderlist.
In this situationen it wasn’t possible to create a new list since a lot of coded things worked with listids. Theres no versioning of dispform.
I first tried to use restore to sitedefinitions, but this kind of change didn’t qualify for making restore for some reason.
So this what came instead.

1. Find a functioning “vanilla” dispform.aspx from a list of same type
2. Open Sharepoint Designer, goto website of above list, find list and copy ListID
3. Find dispform of functioning list and export to file. Save locally on computer
4. Open locally saved dispform with notepad. Find and replace listid of sourcelist with targetlist listID (in calenderar two matches)
5. Opensharepint Designer, goto website of broken list.
6. All Files>Lists><mylist>
7. Take a backup of dispform with export to file, just in case you mess up.
8. Import locally modified dispform
9. Changes take effect immediatly.

References:
https://support.microsoft.com/en-hk/help/2000858/listview-webpart-required-on-dispform.aspx-page-for-document-library

Thursday, July 21, 2016

Script for updating URLrewrite-rules

In these days urlrewrite might not be the first choice for using but I had a situationen where i needed to be applied.
This offered an oppertunity to create a script to automate the addition of custom rules sets for a specific file.
And I got to fiddle with xml-manipulation which is also fun.
This script reads an csv for inputaddress and ruleTemplate file
csv – addresses.csv
ruleName,target,destination
tomteland,www.tomteland.se,tomteland

Powershellscript, this script reads web.config from designated place makes a copy to $workingDir where updates are applied to file in $workingDir. This a pretty specific script, for example outboundRules are applied before <precondition>-tagg, but haven’t really experimented what happens if the preconditions aren’t there for example. So better to use as inspiration rather than copy paste. Also rewriteRules will need to be adjusted for your particuliar scenarios. Matching for rules to change are made with replace() towards #rulename#, #destination and #target# cause this was easier for this scenario.

Monday, July 18, 2016

Finding duplicate content types

Got to a chance to build a script for finding content type duplicates in a Site Collection

#Description:Find duplicate content types in sitecollection

Add-PSSnapin microsoft.sharepoint.powershell

$siteURL = "https://test-mysite.mycompany.com"
$site = get-spsite $siteURL
$object = @()

foreach ($newWeb in $site.AllWebs) {
    foreach ($cType in $newWeb.contentTypes) {
        $tempObj = new-object PSObject -Property @{webURL=$newWeb.Url; CTName=$cType.Name; CTid=$cType.Id}
        $object += $tempObj
        }
    }
#sort out duplicates
$duplicates = $object |Group-Object ctid |Where-Object {$_.count -gt 1} |select -ExpandProperty group

write-output "Found $($object.count) content types in $siteURL"
write-output "Total duplicates: $($duplicates.count)"
$duplicates

Monday, March 14, 2016

Urlrewrite and sharepoint 2013

I some trouble recently getting urlrewrite to play along with SP2013 and IIS 8.
HostNamedSiteCollection wasn’t doable for a lot of other reasons.
Scenario: Using urlrewrites to handle vanityurls for site collections in SP2007. When migrating to SP2013 these rules don’t work at all.

Symptoms: image

  • With outboundrules activated nothing works for webapplication. (Website cannot display the page) 
  • Always lands on top site collection, rewrite dont work.

Solution:
A combination of a few fixes

  • Install patch kb2749660 to fix outboundrules
  • Add registry key ("HKLM:\Software\Microsoft\InetStp\Rewrite\" (Dword) LogRewrittenUrlEnabled=0)
  • Deactivate Static Compression on IIS-site
  • Add rewrite rule like {HTTP_HOST} matches pattern ^www.labb13.nu(.*)

image

References:
https://support.microsoft.com/en-us/kb/2749660 - Response is corrupted when you configure an outgoing rule in URL Rewrite Module 2.0 for IIS 7.0 or IIS 7.5
http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/
https://blogs.msdn.microsoft.com/danielvl/2010/01/07/registry-values-for-iis-url-rewrite/
http://stackoverflow.com/questions/14607390/iis-urlrewrite-is-not-working-for-iis-8
http://social.technet.microsoft.com/wiki/contents/articles/23074.sharepoint-2013-url-rewrite.aspx
http://blogs.technet.com/b/mspfe/archive/2013/11/27/how-to-create-a-url-alias-using-iis-url-rewrite.aspx – example (without sharepoint)
http://johnliu.net/blog/2010/7/23/sharepoint-2010-with-iis-url-rewrite-20.html
https://www.iis.net/learn/extensions/url-rewrite-module/creating-outbound-rules-for-url-rewrite-module
https://social.technet.microsoft.com/Forums/en-US/8d076df4-d93c-47be-80cc-f22dddc1c4c8/how-to-implement-url-rewriting-for-sharepoint?forum=sharepointdevelopmentprevious – similar problem. http://blog.mastykarz.nl/friendly-urls-sharepoint-site-4-steps-iis7-url-rewrite-module/ - rewrite with sharepoint 2013
http://blogs.msdn.com/b/chiranth/archive/2014/06/13/url-rewrite-part-3-outbound-rules-amp-rewrite-maps.aspx - why use outbound rules?
https://support.microsoft.com/sv-se/kb/2818415 - supported assymentrical solutions

Tuesday, January 26, 2016

A fun script for creating meetings in Outlook.
For the very lazy admin

function createMeeting(
    $Subject = "Test Meeting",
    $body = "Just Testing",
    $location = "Here",
    $start = "1/26/2016 12:00 PM",
    $duration = 60,
    $reminderSet = $true,
    $reminderMinutesBeforeStart = 15
    )
{
$olAppointmentItem = 1
$o = New-Object -comobject outlook.application
$a = $o.CreateItem($olAppointmentItem)
$a.MeetingStatus.olMeeting
$a.Start = $start
$a.Duration = $duration
$a.Subject = $Subject
$a.body = $body
$a.Location = $location
$a.ReminderMinutesBeforeStart = $reminderMinutesBeforeStart
$a.reminderSet = $true
$result = $a.Save()
}


$Duration = 60
$Subject = "Test1"
$Body = "testar2"
$Location="Office"
$ReminderMinutesBeforeStart = 30
$reminderSet = $true

#This scenario is set of dates with same meeting time
$arrayOfDates =  "2016-01-26", "2016-01-27","2016-01-28"
$hour = 10
$minute = 00
for ($i=0;$i -le ($ArrayOfDates.count-1);$i++) {
$dateTime = get-date $ArrayOfDates[$i] -Hour $hour -Minute $minute
$dateTime
createMeeting -Subject $Subject -body $Body -location $Location -reminderSet $reminderSet -reminderMinutesBeforeStart $ReminderMinutesBeforeStart -duration $Duration -start $dateTime
}

References:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/077733c5-6e39-489e-908a-d3098c512a71/need-to-create-meeting-request-using-powershell-with-outlook-2010-2013?forum=winserverpowershell

Thursday, November 05, 2015

Script to check databases upgrade status

Ever wonder how the upgrade is doing?
This script checks the status of all Sharepoint-databases.

 

Add-PSSnapin microsoft.sharepoint.powershell

 

$alldatabases  = get-spdatabase

write-output "Status for all databases"

$alldatabases |Sort-Object needsupgrade |select name,webapplication, canupgrade,needsupgrade |format-table -autosize

write-output "Databases needs upgrade: $(($alldatabases |where-object {$_.needsupgrade -like "true"}).count)"

write-output "Timestamp: $(get-date -format "yyyy-MM-dd.HH:mm")"

Powershell and Uptimerobot

Uptimerobot can be quite tedious when you need to update many monitors at once. For example say you bought the license for Uptimerobot and n...