Thursday, February 23, 2017

Get All Web Templates Using PowerShell SharePoint 2013

This script will traverse all the site collections and extract its template name.

1.Site Collections File

Create text file with name “SiteCollections.txt” in the same directory where script file is present.
Write site collections urls in “SiteCollections” file. 
Make it sure each url should be in new line and write “End Point” at the end as shown below.

2. Save Code and Run
Save below code and Open SharePoint Management Shell. Change the directory to where the code and SiteCollections.txt file is saved and run the code script file.

The output would be like below.

PS Script:

[code] $currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."} New-Item $PSScriptRoot\GetAllWebTemplates-$currentTime.txt -type file $SiteCollectionArray = Get-Content -Path $PSScriptRoot\SiteCollections.txt Start-Transcript -Path "$PSScriptRoot\GetAllWebTemplates-$currentTime.txt" $UtilStartTime = "Utility Start Time: " $startTime = Get-Date -Format F $UtilStartTime + $startTime foreach ($url in $SiteCollectionArray) { if($url -ne "End Point") { try{ $site=Get-SPSite -Identity $url } catch {} foreach($web in $site.AllWebs) { if($web) { $output = $site.URL + "`t" + $web.URL + "`t" + $web.WebTemplate + "`t" + $web.WebTemplateId Write-Output $output $web.Dispose() } else { Write-Output "Site Doesn't exist" } } } } $UtilEndTime = "Utility End Time: " $endTime = Get-Date -Format F $UtilEndTime + $endTime Stop-Transcript [/code]

Wednesday, February 22, 2017

SharePoint 2013 Smoke Testing Guide


There are thousands of test cases and a lot of ways for testing SharePoint environment after a fresh installation or any upgrade. However, after each farm level change its necessary to smoke test your SharePoint farm to ensure availability, performance, functionality, security and look & feel.

I would try to cover as much point as i can to smoke test SharePoint farm with Manual Testing. This could apply to all SharePoint environments including MOSS 2007, SharePoint 2010, SharePoint 2013 or SharePoint 2016. Its possible that i could not cover all of the test scenarios at once, but i'll try to keep updating this post time to time and include new test cases.

I would not explain the exact steps to perform a test case here. The purpose of this post is to only highlight the area and components from where SharePoint could be smoke tested.

In current scenario i am testing my SharePoint 2013 environment with compare to SharePoint 2010 environment as i have upgraded this environment. Smoke testing could be performed on below areas in SharePoint.

  1. Security Testing
  2. Functionality Testing
  3. Interface Testing
  4. Performance Testing


Once you have moved the content database to SharePoint 2013 environment successfully, the first thing to test is security as this would be very critical point to check before we say it was a successful migration. Note that, this testing must be performed once you have successfully completed the content DB migration and upgradation steps and  migrated the users from Classic Mode authentication to Claims Based (if your SharePoint 2010 web application was on Classic Mode authentication).

1. Check the migrated sites if users can access them or not after the migration. In ideal case, all of the users should be able to access the migrated sites.
2. Make sure the users which previously has access to the site and its subsites in SharePoint 2010 environment, still have the same access level in SharePoint 2013. This check could be on random sites and sub sites. Specially check for the ones which has unique permissions.
3. Check the random sites and verify that site contains all the users which were present previously in SharePoint 2010. No user, AD Group or SharePoint Group got removed after the migration.
4. Check for the users permission on Web Application from Central Admin. Users that have permissions on Web Application level must retain their permissions.

1. Go to random site or subsites and check if the sites retained their permissions. If a site was uniquely secured in SharePoint 2010, it must have same unique permissions in SharePoint 2013.
2. Check if there is any custom permissions level defined in any site. It must be the same in SharePoint 2013 as in SharePoint 2010.

1. Try to create, provide, change and remove permissions for a user or group. Asks users to test different permissions.

All the testing operations should be performed on SSL URL. Make sure all the newly migrated sites are functional at SSL. No site should be throwing IIS, SharePoint or any other error due to https instead of http.

Once its confirmed that the migrated sites have the same security that was in SharePoint 2010, the next component to test would be its Functionality. Functionality testing includes the general SharePoint functionality testing and custom components testing.

There could be multiple links on the sites pages pointing to other useful areas. Make sure no URL is breaking or pointing to a non-existing place.

Go through random sites' pages to ensure that no page is crashing or breaking up due to any dependency, formatting of data or web part error.

Open custom forms, OOTB item create/ edit/ view forms, popups and dialog boxes. Make sure no one is crashing or bad formatted.

Try to perform CRUD operations on random lists/libraries under random sites to verify there are no errors.

Perform some random search quires in sites search boxes and verify that it’s showing the desired results. Also check if the search result page is not throwing any error or displaying unformatted display.

There would be an output in the form of CSV file in result of following steps of ItemsCounter.docx and ItemsCounter2010.docx. Refer to step 4 of both documents and verify the availability of data from SharePoint 2010 and SharePoint 2013 environments after migration.

There would be an output in the form of CSV file in result of following steps of WorkflowFinder.docx. Refer to step 4 in WorkflowFinder.docx and verify random Workflows exists in SharePoint 2013 environments after migration using SharePoint Designer.

Verify Baseline Components by following the list of components provided in step 3 and their verification method provided in step 4 of “TeamShare Baseline Components Verification.docx” document.

Check and ensure that Content Type Hub site exists responding properly after migration. Make sure its content types are available.

Test Meeting Workspaces in random sites and check if they are not crashing and functioning properly. They should show same components and web parts on main page as they were displaying on SharePoint 2010 environment.

Check if Newsfeed in the top right section of the TeamShare portal navigates to MySite of user. Verify that MySites are available and user can see its profile.

Check the Sites created by using custom site templates and make sure they are functioning properly. There should be no crash or feature dependencies error while creating them.

Check for all custom features installed and try to activation/deactivate them. There should be no crash or error on activation or deactivation.

Target few of random pages in random sites. Try to change/update content of page and then save it. Make sure to revert your changes after this test.

Check for the sites which are not migrating in current content DB and try to browse them. They should redirect you to SharePoint 2010 environment.


Verify that all of the sites have been visually upgraded and new SharePoint 2013 options are available on the sites.

Check all root site collections and few random subsites to verify look and feel after applying new branding.

Verify that new branding is functioning in cross browsers and no page or functionality is breaking.


Browse the site collections and sites inside the migrated database and ensure the response time is normal (due to external data query).

Verify that search queries are entertained and displaying result in an appropriate time.

Check if MySites are loading fine in appropriate time and not crashing due to any timeout errors.

SharePoint 2013 Crawl Rules not Excluding Search Results but matching the rules

This issue happened with me in SharePoint 2013 however i believe the resolution would be the same for SharePoint 2010 and SharePoint 2016 environments.


I have SharePoint 2013 environment and i need to remove all the search results under a specific URL. I created a Crawl Rule to Exclude content, in few cases it did not excluded any content and sometimes it excluded only a partial content. I ran an Incremental Crawl each time i create any rule but same results.


I have site collection under https://webapplication/pa/b and i want to remove all the search results under this URL. This is how i created the rule.

Created the above rule and press OK.

Now for testing if this rules matches our query, i have provided it a sample URL and it matches one of our rule. However, when i ran incremental crawl, the target URL was still appearing in my search results which i didn't want.


If it matches your rules but do not exclude from search results, it means its not being crawled in your Incremental Crawl. It is understood that SharePoint do not crawl each item in Incremental Crawls so you have to manually set that URL to be crawled in next Incremental Crawl.

Go to Search Service Application > Crawl Log > URL View  and put the target URL in it and press Search button. It will show all the results under that URL. Now click the root URL in the results, click the item and click "Recrawl this item in the next crawl".  See below screenshot for more information. 

 Now run the Incremental Crawl on your content source.

After the crawl completes successfully, it should not show any search results under that URL. If you still see any URL in search results, make sure your no other rule is including it or you can copy that exact URL and put it in URL View to check the status of that specific item.

Happy SharePointing :)

Wednesday, February 15, 2017

Count All List/Libraries Items Using PowerShell SharePoint 2013

This PowerShell Script will output all items count inside the provided Site Collections list. It will traverse through Site Collections then all sub sites then all list/libraries and output result in a csv file.

1.Site Collections File

Create text file with name “SiteCollections.txt” in the same directory where script file is present.
Write site collections urls in “SiteCollections” file. 
Make it sure each url should be in new line and write “End Point” at the end as shown below.

2.Open SharePoint 2013 Management Shell

3.Change directory path where script file is saved

Then type ./ItemsCounter.ps1 and press enter key.

It will count all the items of all lists and libraries in site collections which you will provide in “SiteCollection.txt” in first step.

Result will be saved in “ItemsCounter.csv” file which you can find in the same directory where your script file is located.
 You can also track the complete log file (named ItemsCounter-current date and time) which you can find in the same directory where your script file is located. Here is how the result will look like.

PowerShell Script

[code] $currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."} New-Item $PSScriptRoot\ItemsCounter-$currentTime.txt -type file New-Item $PSScriptRoot\ItemsCounter.csv -type file -Force $outputFile = "$PSScriptRoot\ItemsCounter.csv" Write-Output $outputFile $outputHeader = "siteCollection URL" + "`t" + "Site Url" + "`t" +" List Name" + "`t" + " Total Items " > $outputFile $SiteCollectionArray = Get-Content -Path $PSScriptRoot\SiteCollections.txt Start-Transcript -Path "$PSScriptRoot\ItemsCounter-$currentTime.txt" foreach($site in $SiteCollectionArray) { if($site -ne "End Point") { $siteCollection = Get-SPSite -Identity $Site foreach($SPWeb in $siteCollection.AllWebs) { foreach($SPList in $SPWeb.Lists) { $TotalItems = $SPList.ItemCount $output = $Site + "`t" + $SPWeb + "`t" + $SPList + "`t" + $TotalItems Write-Output $output >> $outputFile Write-Output $output } } } } Stop-Transcript [/code]

Friday, February 10, 2017

Change Content of Content Editor WebPart Using PowerShell SharePoint 2013

This PowerShell script will change the content of a content editor webpart based on its title. You can change the title of target webpart as well as in PowerShell script too.

1. Site Collections File

Create text file with name “SiteCollections.txt” in the same directory where script file is present.
Write site collections urls in “SiteCollections” file.
Make it sure each url should be in new line and write “End Point” at the end as shown below. End Point is a reserve word for this script.

  2. Open SharePoint 2013 Management Shell

3.   Change directory path where script file is saved.

4.    Type script name

Copy and Save this script with name like ChangeWebPartContent.ps1 and ps1 extention.
Type ”./ ChangeWebPartContent.ps1 –path “directory path\SiteCollections.txt” –overwrite o “ and press enter key.
Type ”./ ChangeWebPartContent.ps1 –path “directory path\SiteCollections.txt” –overwrite A “ and press enter key.
-overwrite o will over write web part content and –overwrite a will append to web part content. 

[code] param([string]$Path = "", [string]$Overwrite = "") Function ChangeWebPartContent([string]$SPSite, [string]$OverWriteContent) { #Write-Host "Site : " $SPSite " Overwrite : " $OverWriteContent $site=Get-SPSite $SPSite -ErrorAction SilentlyContinue if($site -ne $null) {Write-Host "Web Found: " $site.RootWeb.URL} else{ [console]::ForegroundColor = "Red" write-Host "Web Not Found: " $SPSite [console]::ForegroundColor = "White" } #Loop throgh each subsite in the site collection try{ $file= $web.GetFile($site.RootWeb.RootFolder.WelcomePage) #Write-Host "Found Welcome Page: " $web.URL } catch [System.Exception] { #Write-Host $_.Exception.Message #Write-Host "Unable to get Welcome Page: " $web.URL } foreach($web in $Site.RootWeb) { #Get the Default.aspx file try{ $file= $web.GetFile($web.Url +$web.RootFolder.WelcomePage) } catch { } #Write-Host $file.URL if($file.Exists) { #Web Part Manager to get all web parts from the file $WebPartManager = $web.GetLimitedWebPartManager( $file, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Iterate through each web part foreach($webPart in $WebPartManager.WebParts) { # Get the Content Editor web part with specific Title if( ($webPart.title -eq "My Custom Web Part" -Or $webPart.title -eq "Target Web Part Title" -and ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) ) { try{ #Content to be Placed inside CEWP $HtmlContent= "Hello, this is updated content." $XmlDoc = New-Object System.Xml.XmlDocument $contentXml=$xmlDoc.CreateElement("content") if($OverWriteContent -eq "A") { $HtmlContent = $webpart.Content.InnerText + $HtmlContent } $contentXml.InnerText = $HtmlContent #Set content and Save $webpart.Content = $contentXml $webPartManager.SaveChanges($webPart); [console]::ForegroundColor = "Green" Write-Host "Webpart found: " $web.URL [console]::ForegroundColor = "White" } catch [System.Exception] { #Write-Host $_.Exception.Message [console]::ForegroundColor = "Red" Write-Host "Unable to update webpart: " $web.URL [console]::ForegroundColor = "White" } } } } } } ############################################################################################################################################ $SitesArray = Get-Content -Path ($ScriptPath) $OverWriteData = $OverWrite if($OverWriteData -eq "O" -Or $OverWriteData -eq "A") { for($i=0; $i -le $SitesArray.Length; $i++) { if($SitesArray[$i] -ne "End Point" -And $SitesArray[$i].Length -gt "5") { ChangeWebPartContent $SitesArray[$i] $OverWrite } } } else { [console]::ForegroundColor = "Red" Write-Host "Unknown input, try again...!" [console]::ForegroundColor = "White" } [/code]

Convert Classic To Claims Mode Authentication SharePoint 2013

Your SharePoint 2013 users may get Access Denied while accessing a web application which is just got migrated from SharePoint 2010 environment. Mostly this happens due to change in authentication modes as classic mode authentication has been deprecated in SharePoint 2013. Although you can create a classic mode web application using SharePoint Management Shell.

This script will work on SharePoint 2013 environment where you have a classic mode web application migrated from SharePoint 2010 or MOSS 2007.

Note: If you have more than one Content Databases attached with single web application and you are migrating databases one by one, you have to run this script each time you finish your database migration on SharePoint 2013 environment. This is what i have learned from my recent migration work.

[code]Convert-SPWebApplication -Identity "http://webapplicationurl" -From Legacy -To Claims -RetainPermissions -Force[/code]

Full code with user input and logs. This will export a log file as well.

$currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."}
New-Item $PSScriptRoot\ConvertClassicToClaims-$currentTime.txt -type file
Start-Transcript -Path "$PSScriptRoot\ConvertClassicToClaims-$currentTime.txt"
$WebApplicationUrl = Read-Host "Please provide Web Application URL"
$wa = Get-SPWebApplication $WebApplicationUrl
Convert-SPWebApplication -Identity $wa -To Claims -RetainPermissions -Force

Find All Farm Features With Solution Names Using PowerShell SharePoint 2013

This PowerShell script traverse all the custom solutions deployed in Central Admin and the features that get deployed under that solutions. 

It exports following items.
1. Solution ID
2. Solution Name
3. Feature ID
4. Feature Name
5. Feature Scope

 You can change the paths accordingly.

 [code] Start-Transcript "C:\FeatureLogs.txt" $farm=[Microsoft.SharePoint.Administration.SPFarm]::Local foreach ($solution in $farm.Solutions) { $solId = (Get-SPSolution $solution.DisplayName).Id foreach($featcher in (Get-SPFeature | where {$_.solutionId -eq $solId})) { $SolutionID = $solution.DisplayName $output = $ + "`t" + $solution.DisplayName + "`t" + $ + "`t" + $featcher.DisplayName + "`t" + $featcher.Scope Write-Host $output } } Stop-Transcript [/code]