Tuesday, February 28, 2017

Find attached Workflows to a list in SharePoint 2013 using PowerShell

This Script will iterate through all the provided Site Collections and export the attached Workflows with a list in a CSV file. It will also generate a log file that contains the script execution logs.

It will export the following items.

1. Site URL
2. Web URL
3. List Name
4. Attached Workflows Count




1.Text file containing database names

Create text file with name “DB.txt” in the same directory where script file is present.
Write database names in “DB” file. 
Make it sure each name 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


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

3. Results
2.       Result will be saved in “WorkflowFinder.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 WorkflowFinder -current date and time) which you can find in the same directory where your script file is located. 

Output CSV will look like this.


PowerShell Scipt

[code] $currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."} New-Item $PSScriptRoot\WorkFlowFinder-$currentTime.txt -type file New-Item $PSScriptRoot\WorkFlowFinder.csv -type file -Force $SiteCollectionArray = Get-Content -Path $PSScriptRoot\SiteCollections.txt Start-Transcript -Path "$PSScriptRoot\WorkFlowFinder-$currentTime.txt" $UtilStartTime = "Utility Start Time: " $startTime = Get-Date -Format F $UtilStartTime + $startTime $outputFile = "$PSScriptRoot\WorkFlowFinder.csv" #Initialize Workflow Count variable $workflowcount = 0 $outputHeader = "Site URL" + "`t" + "Web Url" + "`t" +" List Name" + "`t" + " Total Items " > $outputFile #Write-Host $DbArray.Length foreach($siteCol in $SiteCollectionArray) { if($siteCol -ne "End Point") { $SPSite =Get-SPSite -Identity $siteCol foreach($SPWeb in $SPSite.AllWebs) { foreach($SPList in $SPWeb.Lists) { foreach($wf in $SPList.WorkflowAssociations) { if ($wf.Name -notlike "*Previous Version*") { $workflowcount += 1 } } #Write-Host $workflowcount if($workflowcount -gt 0) { $output = $SPSite.Url + "`t" + $SPWeb.Url + "`t" + $SPList.Title + "`t" + $workflowcount >> $outputFile Write-Output $output } $workflowcount = 0 } } } } $UtilEndTime = "Utility End Time: " $endTime = Get-Date -Format F $UtilEndTime + $endTime Stop-Transcript [/code]


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 Manual Smoke Testing Guide

Hi,

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
1. SECURITY TESTING

1.1 CHECK USER ACCESS

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.2 UNIQUE SECURITY CHECK
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.3 NEW PERMISSIONS
1. Try to create, provide, change and remove permissions for a user or group. Asks users to test different permissions.

1.4 SSL CHECK
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.

2. FUNCTIONALITY TESTING
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.

2.1 CHECK ALL LINKS
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.

2.2 SITES AVAILABILITY
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.

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

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

2.5 SEARCH TESTING
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.

2.6 DATA VERIFICATION
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.

2.7 WORKFLOWS TESTING
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.

2.8 BASELINE COMPONENTS
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.

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

2.10 MEETING WORKSPACES TESTING
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.

2.11 MYSITE CHECK
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.

2.12 CUSTOM SITE TEMPLATES
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.

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

2.14 PAGE CONTENT CHANGE
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.

2.15 URL REDIRECT CHECK
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.


3. INTERFACE TESTING

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

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

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

4. PERFORMANCE TESTING

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

4.2 SEARCH RESPONSE TIME
Verify that search queries are entertained and displaying result in an appropriate time.

4.3 MY SITE LOAD
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.

Problem:

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.

Scenario: 

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.



Solution:

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.

4.Result 
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.
Or
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.

[code]
$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
Stop-Transcript
[/code]