Archive for PowerShell Script

SharePoint 2013 Migration: User not able to access after migration from SharePoint 2010 to SharePoint 2013

Scenario:

We have migrated our sites from SharePoint 2010 to SharePoint 2013. After migration, users are not able to access newly migrated site. If we delete user and provide access again, user able to access site. (Fortunately, this was happening on test migration)

Resolution:

The missing link was warning that we overlooked. When we ran PowerShell Test-SPContentDatabase cmdlet, we missed following warning:

Category : Configuration

Error : False

UpgradeBlocking : False

Message : The [SharePoint2013] web application is configured with claims authentication mode however the content database you are trying to attach is intended to be used against a windows classic authentication mode.

Remedy : There is an inconsistency between the authentication mode of target web application and the source web application. Ensure that the authentication mode setting in upgraded web application is the same as what you had in previous SharePoint 2010 web application. Refer to the link http://go.microsoft.com/fwlink/?LinkId=236865 for more information.

Locations :

In other words, SharePoint 2013 discourage classic mode authentication. If web application is created via Central Administration, claim based is the default and preferred method of authentication. If want to create web application with classic mode authentication, you need to use PowerShell cmdlets.

It goes like this:

  1. Create classic mode web application using PowerShell cmdlets
  2. Attach all content database with web application
  3. Convert classis mode web application to claim base authentication
  4. Configure Object cache

Create classic mode web application using PowerShell cmdlets

$ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication –DisableKerberos

New-SPWebApplication -Name “SharePoint – 2013” -ApplicationPool “SharePoint 2013 Web Apps” -ApplicationPoolAccount (Get-SPManagedAccount “domain\login”) -Port 80 -Url http://sharepoint2013 -AuthenticationMethod NTLM -AuthenticationProvider $ap -DatabaseName “WSS_Content_01”

Attach all content database with web application

Mount-SPContentDatabase “WSS_Content_2” -DatabaseServer “SQLDB2013” -WebApplication http://sharepoint2013

Convert classis mode web application to claim base authentication

Convert-SPWebApplication –Identity http://sharepoint2013 –To Claims -RetainPermissions –Force

Configure Object cache

$wa = Get-SPWebApplication -Identity http://sharepoint2013

$wa.Properties[“portalsuperuseraccount”] = “domain\login”

$wa.Properties[“portalsuperreaderaccount”] = “domain\login”

$wa.Update()

Make sure you enter user login using SharePoint 2013 claims encoding. It must be in this format “i:0#.w|contoso\chris” [For details, please visit] and don’t forget to restart IIS.


Leave a Comment

SharePoint 2010: PowerShell script to add in web.config

Scenario:

We need to add an entry in “<assemblies>” section of the “web.config” file of specific web application using power shell script

Resolution:

Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]

[Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]

$WebApplication

)

$WebApp = $WebApplication.Read()

Write-Host $WebApp

$configMod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification

$configMod.Name = “add[@name=””assembly””]”

$configMod.Path = “/configuration/system.web/compilation/assemblies”

$configMod.Value = “<add assembly=””AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e”” />”

$configMod.Sequence = 0

$configMod.Type = 0 #for enum value of SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode

$configMod.Owner = “Ajax”

$WebApp.WebConfigModifications.Add($configMod)

$WebApp.Update()

$WebApp.Parent.ApplyWebConfigModifications()

Resource: http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/14/use-powershell-to-script-changes-to-the-sharepoint-web-config-file.aspx

Comments (1)

SharePoint 2010: PowerShell Script to add / display list as webpart

Scenario:

We were required to add / display discussion forum / discussion board as a webpart on a publishing page.

Resolution:

We used “XsltListViewWebPart” webpart to accomplish above requirement

$webpart New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart

$webpart.ListId $list.ID;

$webpart.ViewGuid $list.DefaultView.ID.ToString();

$webpart.AllowClose $false;

$webpart.AllowConnect $false;

$webpart.AllowEdit $false;

$webpart.AllowHide $false;

$webpart.AllowMinimize $false;

$webpart.AllowZoneChange $false;

$webpart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::None;

$webpartmanager=$web.GetLimitedWebPartManager($pageUrl,

[System.Web.UI.WebControls.WebParts.PersonalizationScope]

::Shared)

$webpartmanager.AddWebPart($webpart, “Zone 1”, 0);

You need to set following variables:

$list = Get the reference of list. In our case, it was discussion forum

$pageUrl = Url of the page

Leave a Comment

SharePoint 2010: PowerShell Script to create Discussion Board / Discussion Forum

Scenario:

We need to create discussion board / discussion forum using power shell script

Resolution:

$spWeb Get-SPWeb $webURL

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DiscussionBoard

$spWeb.Lists.Add(“Discussion Forum”, “Custom List”, [int]$listTemplate)

Thanks to my friend Abdur Raheem 

Comments (1)

PowerShell Script: Enable and Add Content Type in Document Library

Scenario:

We created content types using power shell script. Now, we need to enable content types and add these content types in the list.

Resolution:

$site = Get-SPSite “url of site collection”

$rootWeb $site.RootWeb

$docLib $rootWeb.Lists[“Shared Documents”]

$customContentTypes “ContentType1,ContentType2,ContentType3”

$docLib.ContentTypesEnabled $true

$docLib.update()

$customContentTypeArray $customContentTypes.Split(“,”)

foreach($customContentType in $customContentTypeArray)

{

    $customCT $rootWeb.ContentTypes[$customContentType]

    $docLib.ContentTypes.Add($customCT)

}

$docLib.update()

Comments (3)

PowerShell Script: Change Site Theme

Scenario:

We have customized a site theme as explained in previous post. Now, we need to apply it on Site and all its webs.

Resolution:

$name = [Name of theme]

$filepath = [Path of the theme]

$bytes = [System.IO.File]::ReadAllBytes($filepath + “\” $name);

$site = Get-SPSite(“url of site collection”)

$rootWeb $site.RootWeb

$list $rootWeb.Lists[“Theme Gallery”]

$list.RootFolder.Files.Add($name,$bytes)

$theme = [Microsoft.SharePoint.Utilities.ThmxTheme]::Open

($site,“_catalogs/theme/”$name)


foreach($web in $site.AllWebs)

{

$theme.ApplyTo($web,$false)

}

Leave a Comment

SharePoint 2010: PowerShell Script to Create SiteCollection using Custom Template

Scenario:

We need to write PowerShell script to create site collection using custom template.

Resolution:

First, we need to save site as template. For this, “Site Settings” -> “Save site as template”. Enter site template name, say, testCustomtemplate. After saving, go to “Solution Gallery” and download the testCustomtemplate.wsp.

Second, add the wsp. For this, run SharePoint PowerShell and run following commands:

Add-SPSolution [Path to testCustomtemplate.wsp]

Install-SPSolution –identity testCustomtemplate.wsp

Third, run following script making appropriate changes:

$newSite = New-SPSite -Name [SiteCollectionName] -Url [URL] -OwnerEmail [OwnerMail] -OwnerAlias [OwnerLogin] -SecondaryOwnerAlias [SecondaryOwnerLogin]

Enable-SPFeature -Identity [FeatureGuid] -Url $newSite.Url

$rootWeb = $newSite.RootWeb

$rootWeb.ApplyWebTemplate(“[CustomTemplate]”)

You need to find values of two variables. One is “FeatureGuid” and other is “CustomTemplate”.

FeatureGuid can be found out by simply going to 14 hives, go for folder containing the name “WebTemplate” along with your solution name and copy feature ID. Like we have feature ID {e27e2916-5eb2-4a23-901b-fb3f386136bb}.

CustomTemplate can be manually created by concatenating the name of the solution and feature as under:

{e27e2916-5eb2-4a23-901b-fb3f386136bb}# testCustomtemplate

Or run following simple script after activating the feature on site collection:

$site = Get-SPSite [SiteCollectionURL]

$web = $site.RootWeb

$templates = $web.GetAvailableWebTemplates(1033) //1033 is Culture ID.

Foreach($temaplte in $templates)

{

$template.Name

}

Comments (2)

Older Posts »