Wednesday, December 20, 2017

SharePoint Online: Add Site Column to List using PowerShell

Requirement: Add an existing site column to SharePoint list or library using PowerShell.

How to Add a Site Column to SharePoint Online List?
Site columns in SharePoint provides great re-usability without having to recreate same columns multiple times! Once created at top level site, we can utilize them to store metadata in any number of lists and libraries under the hierarchy. To add a site column to SharePoint list, follow these steps:
  • Go to List Settings >> Under Columns, Click on "Add from existing site columns" link.
  • From the available site columns, pick the required site column(s) and click on Add button.
    sharepoint online powershell to add site column to list
  • Click OK to save your changes.

Add Site Column to List or Library with PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Variables
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$SiteColumnName="Department"

$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$Web = $Ctx.web

#Get the list
$List=$Ctx.Web.Lists.GetByTitle($ListName)
    
#Get the Site column
$Field = $Web.Fields.GetByTitle($SiteColumnName)

#Add the site column to the list
$List.Fields.Add($Field)
$ctx.ExecuteQuery() 
    
Write-host "Site Column Added to the List Successfully!" -f Green
Lets add some error handling to the above code to handle scenarios, such as:
  • What if the given site column doesn't exist?
  • What if the given site column is already added to the list?
  • What if the given list doesn't exist? or what if the given credentials are invalid?, etc.
PowerShell to Add a Site Column to SharePoint List:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$SiteColumnName="Department"

Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    $Web = $Ctx.web

    #Get the Site column from web
    $SiteColumns = $Web.Fields
    $Ctx.Load($SiteColumns)
    $Ctx.ExecuteQuery()
    $SiteColumn = $SiteColumns | Where {$_.Title -eq $SiteColumnName}
    
    #Check if given site column exists
    if($SiteColumn -eq $Null)
    {
        Write-host "Site Column $SiteColumnName doesn't exists!" -f Yellow
    }
    else
    {
        #Get the list
        $List=$Ctx.Web.Lists.GetByTitle($ListName)

        #Check if the Filed exist in list already
        $Fields = $List.Fields
        $Ctx.Load($List)
        $Ctx.Load($Fields)
        $Ctx.ExecuteQuery() 
        $Field = $Fields | where {$_.Title -eq $SiteColumnName}
        if($Field -ne $NULL)  
        {
            Write-host "Column Name $SiteColumnName already exists in the list!" -f Yellow
        }
        else
        {
            #Add the site column to the list
            $NewColumn = $List.Fields.Add($SiteColumn)
            $ctx.ExecuteQuery() 
    
            Write-host "Site Column Added to the List Successfully!" -f Green
        }
    }
}
Catch {
    write-host -f Red "Error Adding Site Column to List!" $_.Exception.Message
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, November 28, 2017

How to Add a Custom Tile to SharePoint 2016 App Launcher

Requirement: Add new tile to App Launcher in SharePoint Online.

How to Add a Custom Tile to SharePoint 2016 App Launcher?
We wanted to place a new tile in SharePoint 2016 app launcher for support center site, as an end-user usability improvement. SharePoint 2016 Feature Pack 1 brought us the capability to add new tile to app launcher. Here is how you can customize SharePoint 2016 App launcher.

Step 1: Enable the "Custom Tiles" feature in SharePoint 2016 with PowerShell:
Use this PowerShell script to enable custom tiles feature. 
Enable-SPFeature -Identity CustomTiles -Url "http://intranet.crescent.com" -Force
This creates a new list "Custom Tiles" in the given web application's root site collection.

Step 2: Create new Tile in "Custom Tiles" list
Once the feature is activated, navigate to: http://intranet.crescent.com/Lists/Custom%20Tiles/AllItems.aspx URL and add a new entry with desired URL and image for tile for your custom tile. Please note, this list is hidden from browser interface, so you should use the link to directly in the browser to navigate to the list.sharepoint 2016 app launcher customize

It may take up to 24 hours for the new tile to reflect. Clear your browser cache, or open the browser in Private mode to see the new tile in action.
how to add custom tile in sharepoint 2016





You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, November 12, 2017

SharePoint Online: Grant Permission to List Item using PowerShell

Permissions are hierarchical in SharePoint from Top Site collection till the List Item level. To set unique permissions on list items, you need to configure permissions on item level. Here is how:

How to Grant Access to Individual List Items in SharePoint Online?
Got a business requirement to grant permissions at List item level. To set explicit permissions on SharePoint online list items, we need to break the permission inheritance first (stop inheriting permissions) and then add user or group to the List Item.
  • Go to your SharePoint Online list or library >> Select the Item to which you want to provide unique permissions. 
  • Click on "Shared With" button from the ribbon. On the Shared With page, click Advanced.
    set item level permission in sharepoint online
  • On the Permissions tab, in the Inheritance group, click Stop Inheriting Permissions button. Confirm the prompt.
    sharepoint online list item permissions powershell
  • Now, from the ribbon, click on "Grant Permissions." button. In the Share dialog box, enter names, email addresses. Click the Show Options button. In the Select A Permission Level list box, select appropriate permission level such as Edit.
    powershell to grant permission to list item in sharepoint online
  • Click Share.
Having too many Item level permissions often leads to performance issues! so, be careful.

SharePoint Online: Set List Item Permissions using PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#To call non-generic method Load(list, x => x.HasUniqueRoleAssignments)
Function Invoke-LoadMethod() {
    param(
            [Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"),
            [string]$PropertyName
        ) 
   $ctx = $Object.Context
   $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load") 
   $type = $Object.GetType()
   $clientLoad = $load.MakeGenericMethod($type)

   $Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name)
   $Expression = [System.Linq.Expressions.Expression]::Lambda([System.Linq.Expressions.Expression]::Convert([System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName),[System.Object] ), $($Parameter))
   $ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1)
   $ExpressionArray.SetValue($Expression, 0)
   $clientLoad.Invoke($ctx,@($Object,$ExpressionArray))
}

Function Set-ListItemPermission
{
    param
    (   
        [Parameter(Mandatory=$true)] [string]$SiteURL,
        [Parameter(Mandatory=$true)] [string]$ListName,
        [Parameter(Mandatory=$true)] [string]$ItemID,
        [Parameter(Mandatory=$true)] [string]$PermissionLevel,
        [Parameter(Mandatory=$true)] [string]$UserID
    )
    Try {
        #Setup Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get the List and Item
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $ListItem=$List.GetItemByID($ItemID)
        $Ctx.Load($List)
        $Ctx.Load($ListItem)
        $Ctx.ExecuteQuery()

        #Check if Item has unique permission already
        Invoke-LoadMethod -Object $list -PropertyName "HasUniqueRoleAssignments"
        $Ctx.ExecuteQuery()

        #Break Item's permision Inheritance, if its inheriting permissions from the parent
        if (-not $ListItem.HasUniqueRoleAssignments)
        {
            $ListItem.BreakRoleInheritance($false, $false) #keep the existing permissions: No -  Clear listitems permissions: No
            $ctx.ExecuteQuery()
        }

        #Get the User
        $User = $Ctx.Web.EnsureUser($UserID)
        $Ctx.load($User)
        $Ctx.ExecuteQuery()

        #Get the role 
        $Role = $Ctx.web.RoleDefinitions.GetByName($PermissionLevel)
        $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
        $RoleDB.Add($Role)
         
        #Assign permissions
        $UserPermissions = $ListItem.RoleAssignments.Add($User,$RoleDB)
        $ListItem.Update()
        $Ctx.ExecuteQuery()
    
        Write-host -f Green "Permission granted to List Item successfully!"
    }
    Catch {
        Write-host -f Red "Error granting permission to List Item!" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$ItemID="1"
$UserID="salaudeen@crescent.com"
$PermissionLevel="Edit"

#Call the function
Set-ListItemPermission -SiteURL $SiteURL -ListName $ListName -ItemID $ItemID -UserID $UserID -PermissionLevel $PermissionLevel 

This script grants permission on Item level for given user. If you want to provide permission to SharePoint Group, Instead of line
$User = $Web.EnsureUser($UserAccount)
#use:
$Group =$Web.SiteGroups.GetByName($GroupName)
#and then
$GroupPermissions = $Item.RoleAssignments.Add($Group,$RoleDB)


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, October 11, 2017

Create Search Service Application in SharePoint 2016 Multi-Server Farm using PowerShell

The Search Service Application in SharePoint provides search functionality, as its name implies. We have to use PowerShell scripts to configure search service application from SharePoint 2013 on wards as there is no user interface to configure the Search topology from SharePoint Central Admin - although we can create new search service application instance.

Configuring SharePoint 2016 Search Service Application for Multi-Server Farm:

While my earlier article addresses How to create search service application in SharePoint 2013 - Single Server farm, for Standalone SharePoint 2013 or SharePoint 2016 installations, In a production environment we may have to distribute and load balance search components to different servers in a multi-server farm.

Here is the proposed Farm search topology in high level:
create sharepoint 2016 search service application with Powershell

I've the below servers in my SharePoint 2016 environment using Shared MinRoles:
  • Web Front End + Distributed Cache Servers - 2
  • Application + Search Servers - 2
Since we'll be using multiple servers in SharePoint farm, we can add Redundancy, Performance, and Reliability  to the search application by splitting the six search components (Admin, Crawl, Content Processing, Indexing, Analytics, and Query Processing) among them. Also, we will configure two index partitions to ensure both servers have a replica of the search index.

PowerShell to Configure Search Service Application in SharePoint 2016:
Modifications to the search topology requires a decent understanding of SharePoint search topology as well as PowerShell. Here is the PowerShell script to create search service application in a multi-server SharePoint 2016 environment. You can add or modify the topology components according to your environment. Lets take an example. In my case we've two SharePoint Search App Servers to host all search components. Creating search service application for SharePoint 2016 involves these steps at high level:
  1. Creating Managed account, application pool for search service application.
  2. Creating SharePoint Search Service Application & Proxy
  3. Starting Search service instance on all servers participating search topology
  4. Creating an Search Topology and adding Search components and then Activating the search topology
Create Search Service Application using PowerShell:
Here is the PowerShell script to create SharePoint 2016 search service application.
Copy-Paste this script to PowerShell ISE or any other PowerShell editor (PowerGUI?), set the configuration parameters according to your environment and run one step at a time!

Create folders for Index Location & Replica Location (as in variables: $PrimaryIndexLocation & $ReplicaIndexLocation) on all servers which are hosting search topology index components, prior running the main script!
#Set the primary and replica index locations
$PrimaryIndexLocation = "D:\SearchIndex"
$ReplicaIndexLocation = "E:\SearchIndexReplica"

#Prepare Index Locations
Remove-Item -Recurse -Force -LiteralPath $PrimaryIndexLocation -ErrorAction SilentlyContinue
MKDIR -Path $PrimaryIndexLocation -Force
Remove-Item -Recurse -Force -LiteralPath $ReplicaIndexLocation -ErrorAction SilentlyContinue
MKDIR -Path $ReplicaIndexLocation -Force

PowerShell Script to Configure Search Service Application in SharePoint 2016:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Region Config_Parameters
#Settings for Search Service Application
$SearchServiceApplicationName = "Search Service Application"
$SearchServiceApplicationProxyName = "Search Service Application Proxy"
$SearchAppPoolAccount = "Crescent\SP16_Services"
$SearchDatabaseServer = "SP16_SQL"
$SearchServiceApplicationDatabase = "Crescent_Search_ServiceApp"
$SearchAppPoolName = "Service Application App Pool"

#Farm Server topology: App with Search role: 2
$SearchAppServer1 = "SP16-APPSrv01"
$SearchAppServer2 = "SP16-APPSrv02"

#Set the primary and replica index locations
$PrimaryIndexLocation = "D:\SearchIndex"
$ReplicaIndexLocation = "E:\SearchIndexReplica"
#EndRegion


#*** Step 1: Create Managed Account, Service Application Pool for Search Service Application **** 
#Check if Managed account is registered already
Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists..."
$SearchAppPoolAccount = Get-SPManagedAccount -Identity $SearchAppPoolAccount -ErrorAction SilentlyContinue
If ($SearchAppPoolAccount -eq $null)
{
    Write-Host "Please Enter the password for the Service Account..."
    $AppPoolCredentials = Get-Credential $SearchAppPoolAccount
    $SearchAppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
    write-host "Managed Account has been Created!" -ForegroundColor Green
}

#Try to Get the existing Application Pool
Write-Host -ForegroundColor Yellow "Checking if the App Pool already exists..."
$SearchServiceAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue
#If Application pool Doesn't exists, Create it
if ($SearchServiceAppPool -eq $Null)
{ 
    $SearchServiceAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccount 
    write-host "Created New Service Application Pool!" -ForegroundColor Green
}

#*** Step 2: Start Search Service Instances on required servers ***
Write-host "Starting Service Instances..." -ForegroundColor Green
#Search App Server 1
$SearchAppInstance1 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer1
if(-not($SearchAppInstance1.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer1..." -NoNewline
    $SearchAppInstance1 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance1.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance1 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer1
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer1"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer1 -ErrorAction SilentlyContinue

#Search App Server 2
$SearchAppInstance2 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer2
if(-not($SearchAppInstance2.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer2..." -NoNewline
    $SearchAppInstance2 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance2.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance2 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer2
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer2"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer2 -ErrorAction SilentlyContinue


#*** Step 3: Create Search Service Application and proxy**** 
Write-host "Creating Search Service Application..." -ForegroundColor Yellow
# Get the Search Service Application
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceApplicationName -ErrorAction SilentlyContinue
# Create the Search Service Application, If it doesn't exists! 
if(!$SearchServiceApplication)
{
    $SearchServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceApplicationName -ApplicationPool $SearchServiceAppPool -DatabaseServer $SearchDatabaseServer -DatabaseName $SearchServiceApplicationDatabase
    write-host "Created New Search Service Application" -ForegroundColor Green
}

#Get the Search Service Application Proxy
$SearchServiceAppProxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceApplicationProxyName -ErrorAction SilentlyContinue
# Create the Proxy, If it doesn't exists! 
if(!$SearchServiceAppProxy)
{
    $SearchServiceAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name $SearchServiceApplicationProxyName -SearchApplication $SearchServiceApplication 
    write-host "Created New Search Service Application Proxy" -ForegroundColor Green
}

#*** Step 4: Create New Search Topology and add components to it
Write-Host -ForegroundColor Yellow "Creating Search Service Topology..."
# Create New Search Topology 
$SearchTopology =  New-SPEnterpriseSearchTopology -SearchApplication $SearchServiceApplication

#Admin Component:App 01 & 02
New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Content Processing:App 01 & 02
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Analytics processing:App01 & 02
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Crawl components:App 01 & 02
New-SPEnterpriseSearchCrawlComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchCrawlComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Query processing: App 01 & 02
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2

#Create Index Components : App 01 & 02
#Two index partitions and replicas for each partition
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1 -RootDirectory $PrimaryIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2 -RootDirectory $ReplicaIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance2 -RootDirectory $PrimaryIndexLocation -IndexPartition 1
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance1 -RootDirectory $ReplicaIndexLocation -IndexPartition 1

#Activate the Toplogy for Search Service
$SearchTopology.Activate() # Or Use: Set-SPEnterpriseSearchTopology -Identity $SearchTopology

#Remove all inactive topologies
$InactiveTopologies = Get-SPEnterpriseSearchTopology -SearchApplication $SearchServiceApplication | Where {$_.State -ne "Active"}
$InactiveTopologies | Remove-SPEnterpriseSearchTopology -Confirm:$false

Write-Host -ForegroundColor Green "Search Service Application has been created. Please start a Full Crawl!"

Once everything is setup, You can see the Search topology visually from SharePoint Central Administration site.
sharepoint 2016 configure search service application powershell

Scale-out SharePoint 2016 Search to Multiple Servers:
The above script is for SharePoint farm with two "Application with Search" Server. What if your SharePoint farm has more than two app servers, say Four?
Best Practice: Assign Query and Index components together in the same server(s) and place remaining components to other Search App servers.
create sharepoint 2016 search service application
Also, in the script do below changes: Farm Topology Section, include two more servers: Say, App03 and App04
#Farm Server topology: App+Search: 4
$SearchAppServer1 = "Cre-SP16App01"
$SearchAppServer2 = "Cre-SP16App02"
$SearchAppServer3 = "Cre-SP16App03"
$SearchAppServer4 = "Cre-SP16App04"
Start Service instances on app servers 3 & 4 :
#Search App Server 3
$SearchAppInstance3 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer3
if(-not($SearchAppInstance3.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer3..." -NoNewline
    $SearchAppInstance3 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance3.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance3 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer3
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer3"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer3 -ErrorAction SilentlyContinue
#Search App Server 4
$SearchAppInstance4 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer4
if(-not($SearchAppInstance4.Status -eq "Online"))
{
    Write-Host -ForegroundColor Yellow "Starting Search Service instance on $SearchAppServer4..." -NoNewline
    $SearchAppInstance4 | Start-SPEnterpriseSearchServiceInstance
    while ($SearchAppInstance4.Status -ne "Online")
    {
        Write-Host -ForegroundColor Green "." -NoNewline
        Start-Sleep -Seconds 5
        $SearchAppInstance4 = Get-SPEnterpriseSearchServiceInstance $SearchAppServer4
    }
    Write-Host -ForegroundColor Green "Started Search Service instance on $SearchAppServer4"
}
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $SearchAppServer4 -ErrorAction SilentlyContinue 
On creating Search topology: Assign Query and Index Roles to App Servers 3 and 4
#Query processing: App 03 & 04
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4

#Create Index Components : App 03 & 04
#Two index partitions and replicas for each partition
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3 -RootDirectory $PrimaryIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4 -RootDirectory $ReplicaIndexLocation -IndexPartition 0
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance4 -RootDirectory $PrimaryIndexLocation -IndexPartition 1
New-SPEnterpriseSearchIndexComponent –SearchTopology $SearchTopology -SearchServiceInstance $SearchAppInstance3 -RootDirectory $ReplicaIndexLocation -IndexPartition 1

Next Steps:
  • Create Content Sources and schedules 
  • Create Search centre site 
  • Configure Crawl account & search center URL for the Search service application


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, October 9, 2017

SharePoint Online: Rename Files in Document Library using PowerShell

Requirement: Rename files in SharePoint document library using PowerShell
sharepoint online rename file in document library

PowerShell CSOM Script to rename a file in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Set Variables for Site URL, Old File Name and New File Name
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$OldFileURL="/sites/Sales/Documents/Legal.docx"
$NewFileURL="/sites/Sales/Documents/LegalTemplate.docx"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Rename the File
    $File = $Ctx.Web.GetFileByServerRelativeUrl($OldFileURL) 
    $File.MoveTo($NewFileURL, [Microsoft.SharePoint.Client.MoveOperations]::Overwrite) 
    $Ctx.ExecuteQuery()

    write-host -f Green "File Renamed successfully!"
}
Catch {
    write-host -f Red "Error Renaming File!" $_.Exception.Message
}

This script renames the given document to new name. How about renaming all files from a SharePoint online document library?

SharePoint online rename files in bulk using PowerShell:
Say in SharePoint online, you want to rename all documents which has a specific string in their names. 
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Set Variables for Site URL, Library Name and Item ID
$SiteURL= "https://crescent.sharepoint.com/sites/sales/"
$LibraryName="Documents"
$OldString="National"
$NewString="Crescent"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the web and Library
    $Web=$Ctx.Web
    $List=$web.Lists.GetByTitle($LibraryName)

    #Get all items
    $Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $ListItems = $List.GetItems($Query)
    $Ctx.Load($ListItems)
    $Ctx.ExecuteQuery()

    #Rename each file matching given old string
    Foreach($Item in $ListItems)
    {
        #Replace string in the File Name
        if($Item["FileRef"].ToString().Contains($OldString))
        {
            $CurrentURL=$Item["FileRef"].ToString()
            $NewURL = $CurrentURL.Replace($OldString,$NewString) 
            $Item.File.MoveTo($NewURL, [Microsoft.SharePoint.Client.MoveOperations]::Overwrite) 
            $ctx.ExecuteQuery()
            Write-host -f Green "Renamed: "$CurrentURL
        }
    }
}
Catch {
    write-host -f Red "Error Renaming File!" $_.Exception.Message
} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 24, 2017

Create User Profile Service Application using PowerShell in SharePoint 2016

We need User Profile Service Application to consume social features in SharePoint 2016 such as My Sites, User profiles, etc. This PowerShell script creates User Profile Service Application in SharePoint 2016.
Prerequisite: Create my site host prior creating user profile service application.

PowerShell to create user profile service application in SharePoint 2016
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
#Configuration Parameters
$ServiceAppName = "User Profile Service Application"
$ServiceAppProxyName = "User Profile Service Application Proxy"
$AppPoolAccount = "Crescent\SP16_Pool"
$AppPoolName = "Service Application App Pool"
$DatabaseServer ="SP16-SQL"
$UserProfileDB = "Farm_Profile_DB"
$UserProfileSyncDB = "Farm_Profile_Sync_DB"
$UserProfileSocialDB = "Farm_Profile_Social_DB"
$MySiteHostLocation="http://mysite.crescent.com/"

Try {
    #Set the Error Action
    $ErrorActionPreference = "Stop"
   
    #Check if Managed account is registered already
    Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists"
    $AppPoolAccount = Get-SPManagedAccount -Identity $AppPoolAccount -ErrorAction SilentlyContinue
    if($AppPoolAccount -eq $null)
    {
        Write-Host "Please Enter the password for the Service Account..."
        $AppPoolCredentials = Get-Credential $AppPoolAccount
        $AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
    }
   
    #Check if the application pool exists already
    Write-Host -ForegroundColor Yellow "Checking if the Application Pool already exists"
    $AppPool = Get-SPServiceApplicationPool -Identity $AppPoolName -ErrorAction SilentlyContinue
    if ($AppPool -eq $null)
    {
        Write-Host -ForegroundColor Green "Creating Application Pool..."
        $AppPool = New-SPServiceApplicationPool -Name $AppPoolName -Account $AppPoolAccount
    }
   
    #Check if the Service application exists already
    Write-Host -ForegroundColor Yellow "Checking if User Profile Service Application exists already"
    $ServiceApplication = Get-SPServiceApplication -Name $ServiceAppName -ErrorAction SilentlyContinue
    if ($ServiceApplication -eq $null)
    {
        Write-Host -ForegroundColor Green "Creating User Profile Service  Application..."
        $ServiceApplication =  New-SPProfileServiceApplication -Name $ServiceAppName -ApplicationPool $AppPoolName -ProfileDBName $UserProfileDB -ProfileSyncDBName $UserProfileSyncDB -SocialDBName $UserProfileSocialDB -MySiteHostLocation $MySiteHostLocation
    }
    #Check if the Service application Proxy exists already
    $ServiceAppProxy = Get-SPServiceApplicationProxy | where { $_.Name -eq $ServiceAppProxyName}
    if ($ServiceAppProxy -eq $null)
    {
        #Create Proxy
        $ServiceApplicationProxy = New-SPProfileServiceApplicationProxy -Name $ServiceAppProxyName -ServiceApplication $ServiceApplication -DefaultProxyGroup        
    }
    #Start service instance
    $ServiceInstance  = Get-SPServiceInstance | Where-Object { $_.TypeName -eq "User Profile Service" }
   
    #Check the Service status
    if ($ServiceInstance.Status -ne "Online")
    {
        Write-Host -ForegroundColor Yellow "Starting the User Profile Service Instance..."
        Start-SPServiceInstance $ServiceInstance 
    }
   
    Write-Host -ForegroundColor Green "User Profile Service Application created successfully!"
}
catch {
    Write-Host $_.Exception.Message -ForegroundColor Red
 }
 finally {
    #Reset the Error Action to Default
    $ErrorActionPreference = "Continue"
 } 
Once the script execution completed successfully, you can go to Central Administration >> Application Management >> Service Application Page to verify user profile service application is created.
sharepoint 2016 create user profile service application powershell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, June 7, 2017

SharePoint Online: Site Users and Groups Report using PowerShell

Requirement:
Generate a report with all site groups and members of each group of a SharePoint online site collection.
sharepoint online users and groups report using powershell
Prerequisites: Make sure you have SharePoint Online Management Shell installed!

Get all Site Groups and Members of Each group:
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "spadmin@crescent.com"
$SiteURL="https://crescent.sharepoint.com/sites/sales"
 
#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#Get all Site groups
$SiteGroups = Get-SPOSiteGroup -Site $SiteURL

#Get Members of each group
foreach($Group in $SiteGroups)
{
    Write-host "Group:"$Group.Title
    Get-SPOSiteGroup -Site $SiteURL -Group $Group.Title | Select-Object -ExpandProperty Users
} 
To get all users of the site collection, use:
Get-SPOUser -Site $siteURL | select DisplayName, LoginName | Where { $_.LoginName -like "*@crescent.com"}

Get Users and Groups for all SharePoint Online Site Collections:
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Variables for processing
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "SPAdmin@Crescent.com"
 
#User Name & Password to connect
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

Try {
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#Get all Site collections
Get-SPOSite -Limit ALL | ForEach-Object {
Write-Host "Site Collection:"$_.URL

#Get all Site Groups 
$SiteGroups = Get-SPOSiteGroup -Site $_.URL
   
    #Get Members of each group
    foreach($Group in $SiteGroups)
    {
        Write-host "Group:"$Group.Title
        Get-SPOSiteGroup -Site $_.URL -Group $Group.Title | Select-Object -ExpandProperty Users
    }
  }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

SharePoint online groups and permissions report
Lets get all groups along with permissions and members of each group which has access to the site
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Variables for SharePoint Online Admin & Target site collection
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteCollURL="https://crescent.sharepoint.com/sites/sales"

#Get the Credentials
$Credential = Get-credential
#Connect To SharePoint Online 
Connect-SPOService -url $AdminSiteURL -Credential $Credential

#Get the Site collection
$Site = Get-SPOSite $SiteCollURL

#Get all Groups of the site collection     
$GroupColl = Get-SPOSiteGroup -Site $Site | Where { $_.Roles -ne $NULL -and $_.Users -ne $NULL}

Foreach($Group in $GroupColl)
{
    #Get Permissions assigned to the Group
    $GroupPermissions=""
    ForEach($Role in $Group.Roles)
    {
        $GroupPermissions+= $Role+";"
    }
    Write-host -f Yellow "Group Name: $($Group.Title) - Permissions: $($GroupPermissions)"

    #Get each member of the group
    foreach($User in $Group.Users)
    {
         write-host -f Green $user
    }               
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, June 5, 2017

SharePoint Online: How to Change List to New Experience?

SharePoint Online's new list experience provides faster and easier user interface to lists and libraries. You can switch between classic & new experiences in SharePoint online by simply changing list settings.

To change list or library to new modern user interface:
  • Go to List or Library settings >> Click on "Advanced Settings"
  • Scroll down to the bottom, and from "List experience" section, Select "New experience" option and hit OK.
This changes the list UI to new experience in SharePoint online, From:
To: New list experience in SharePoint online


How about setting the default option for all New Lists?
To set list experience for new lists, you can specify this option globally using using SharePoint Admin Center. Here is how:
  • Navigate to your SharePoint Admin Center(typically: https://YOURCOMPANY-admin.sharepoint.com/)
  • Click on "Settings" from the Left navigation
  • On the Setting page, under "SharePoint list and libraries experience" section, Select the appropriate option, such as : Classic experience or New experience (auto detect).

PowerShell script to Switch UI experience of a List or Library in SharePoint Online:
On any existing SharePoint online lists and libraries, you can switch the UI experience either using SharePoint web UI method as explained above or with below PowerShell script. 

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/sales"
$ListName= "Project Documents"
$UserName="salaudeen@crescent.com"
$Password ="Password goes here"
 
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

Try { 
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
    $Context.Credentials = $credentials

    #Get the document library
    $List = $Context.web.Lists.GetByTitle($ListName)
    #Set list properties
    $List.ListExperienceOptions = "NewExperience" #ClassicExperience or Auto
    $List.Update()

    $context.ExecuteQuery()

    Write-host "UI experience updated for the list!" -ForegroundColor Green        
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

SharePoint online new experience not working?
In some cases, even after you changed the list experience settings from list settings, you will be still getting the same UI. This is because of the browser cookie! To fix the problem, simple clear your browse cookie and reload the page. (To be specific, the cookie is called "spInu" with a value of 0!)

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, April 16, 2017

Style SharePoint 2016 List View Web Part with Custom CSS

Requirement: Add a custom style to SharePoint 2016's standard list view web part to make it look like a dashboard!

By default, SharePoint list view web part looks dull, isn't it?
sharepoint 2013 list view web part css
So, lets add some custom CSS to the SharePoint 2016 list view, to make it look like a dashboard! How to add CSS to listview? Simple,
  • Click on Site Settings gear >> Edit Page
  • Insert web part >> Choose "Script Editor" under "Media and Content"
  • Place the below CSS code in it. Save and close!
CSS to Brand SharePoint List view:
<style type="text/css">

/* List View Header */
.ms-listviewtable > thead > tr > th {
 background-color: #5B9BD5;
}

/* List view Header Text color*/
.ms-vh-div,  .ms-headerSortTitleLink {
color:white!important; font-weight: bold;
} 

/* background color for alternate rows */
.ms-listviewtable > tbody > tr.ms-alternating {
background: #DDEBF7
}
</style>

Here is the output of the branded List view web part:
sharepoint 2013 add css to listview
Same CSS works for SharePoint 2013 as well.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, March 30, 2017

Find and Replace User ID in SharePoint InfoPath Forms using PowerShell

Requirement: Replace User IDs in InfoPath Forms.

Little background: A particular user's User account changed in Active directory and in SharePoint we ran Move-SPUser cmdlet to accommodate the user's SAM account name change. However, There are many InfoPath form libraries with bunch of InfoPath forms in it - with old user id. Of course, Move-SPUser has no effect on InfoPath Forms!

PowerShell script to search and replace user id in InfoPath XML Forms:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteCollURL="http://intranet.crescent.com"

#Old and New User IDs - CASE SENSITIVE!
$OldUserID="<pc:AccountId>i:0#.w|Crescent\JohnA</pc:AccountId>"
$NewUserID="<pc:AccountId>i:0#.w|Crescent\JonhAbraham</pc:AccountId>"

#Get all webs in the site collection
$WebsColl = Get-SPSite $SiteCollURL | Get-SPWeb -Limit All

#Iterate through each web
foreach($web in $WebsColl)
{
    Write-host "Processing web:"$web.Url
    
    #Get all InfoPath Form Libraries in the web
    $InfoPathLibs = $web.lists | where { $_.BaseType -eq "DocumentLibrary" -and $_.BaseTemplate -eq "XMLForm"} 

    #Loop through each InfoPath form library and Forms (.xml)
    Foreach($Library in $InfoPathLibs)
    {
        Foreach($Item in $Library.Items)
        {
            # Load the contents of the InfoPath Form
            $File = $Item.File
            $Data = [System.Text.Encoding]::ASCII.GetString($File.OpenBinary())
            
            #Check if the File has Old ID
            if($data.Contains($OldUserID))
            {
                $Data = $Data.Replace($OldUserID, $NewUserID)
                $Data = $Data.Replace("???","") #special fix!
                $File.SaveBinary([System.Text.Encoding]::ASCII.GetBytes($Data))

                Write-host "InfoPath XML File updated at $($web.URL)/$($Item.File.URL)"
            }
        }
    }
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, March 21, 2017

SharePoint Online: Create a Document Library or List with New Experience UI using PowerShell-CSOM

The new list and library experience in SharePoint Online improves the user experience by providing many features such as navigation, fast response, mobile UI, easier to use, etc. You can switch between classic & new experiences anytime. Here is the PowerShell-CSOM script to create a document library in SharePoint online with new experience UI.

PowerShell Script to create a document library in new experience UI:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/Projects"
$UserName="salaudeen@crescent.com"
$Password ="Password goes here"
 
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

Try { 
    #Set up the context
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
    $Context.Credentials = $credentials

    #Create new document library
    $ListInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $ListInfo.Title = "Project Documents"
    $ListInfo.TemplateType = 101 #Document Library
    $List = $Context.Web.Lists.Add($ListInfo)
    
    #Set "New Experience" as list property
    $List.ListExperienceOptions = "NewExperience" #Or ClassicExperience
    $List.Update()
    $Context.ExecuteQuery()

    Write-host "New Document Library Created!" -ForegroundColor Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
} 

This creates a new library "Project Documents" in modern new experience UI.
sharepoint online new list experience


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, March 8, 2017

Fix "Unfortunately, help seems to be broken...There aren't any help collections in the current language for the site you're using." Error in SharePoint 2016

Problem: The Help Menu (?) in SharePoint 2016 is not working! On clicking the Help menu, it gets the error message:
"Unfortunately, help seems to be broken... There aren't any help collections in the current language for the site you're using."
Unfortunately, help seems to be broken... There aren't any help collections in the current language for the site you're using.

Troubleshooting Steps: 
  • Enable External Web-based Help in Privacy Options of SharePoint 2016 Central Admin. Navigate to : http://central-admin-url/_admin/privacy.aspx, and Set "Yes" to "Display Help from external web Sites as specified by each Help collection?"
  • Check the help collection status and install if needed: Open SharePoint 2016 Management Shell, Run:
    Get-SPHelpCollection 

    It gave nothing. Guess help collection is not installed. Now, Install help collection by running:
    Install-SPHelpCollection -All 
wait for few minutes to get them installed (10 min!). Try close and reopen the SharePoint 2016 sites! Now, SharePoint 2016 help should work.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, February 22, 2017

Rich Text Column in SharePoint Document Library

Problem:
Could not add rich text columns to SharePoint document library, Picture Library and other type of Libraries!

Little background: End user created in document library with type "Description" column as "Multiple lines of text"and expecting this column to is expecting to have the Rich text capability. so, tried editing the column, and found no option to update the type of this column as rich text!
rich text field in sharepoint document library
Troubleshooting:
When you add a Multiple lines of text field to custom list, announcement, tasks, etc, You'll find the Rich text and Enhanced rich text options.
rich text field in sharepoint 2013 document library
However on document libraries, these options seems missing! It just displays a Text area without any formatting! It seems you can't have a rich text column in a document library with SharePoint 2013. So, How do we create Rich Text column for a Document Library?
sharepoint document library rich text field
Solution:
While there are many options to get rich text field in SharePoint 2013 document library like: Custom field types, Content Types, etc, here is the easiest way:
  • Open the site in SharePoint designer, Go to List & Libraries, Click on your library
  • Click on Edit columns under Customization >> Double click on the column which you want enable Rich Text functionality >> select the checkbox which says Rich Text and hit OK and then Save.
sharepoint 2013 document library rich text column
This fixes the problem!

PowerShell way: Setting "RichText" property of the field to True makes SharePoint 2013 document library field rich text enabled!
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SiteURL = "http://intranet.crescent.com/"
$ListName="Documents"
$FieldName="Description" #Internal Name

$Web = Get-SPWeb $SiteURL
$List = $Web.Lists[$ListName]
$Field = $List.Fields[$FieldName]
$Field.RichText = $True
$Field.Update()
sharepoint 2013 document library rich text column
I know this issue exists in all SharePoint versions: Including SharePoint 2007, SharePoint 2010, SharePoint 2013 and even in SharePoint 2016! and Yes, It's weird and I'm not sure why Microsoft hasn't fixed this issue yet!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 19, 2017

Compare SharePoint List Item Version History using PowerShell

Requirement: Compare version history data of SharePoint List items and update a metadata column based on a particular field's value change.

Bit background: We've a project tracking list with "Status" column. We wanted to have a insight on when a particular item's status was set to "Rejected".

PowerShell to Compare Version History Data and update a Column value:
As far solution to the above requirement, lets compare list item versions to capture when a particular item's "status" column was changed to "rejected", and get the created date of the specific version to update "Rejected Date" column of the list item. Lets compare version history in SharePoint using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Parameters
$SiteURL="http://intranet.crescent.com"
$ListName = "Projects"

#Get web and List 
$Web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

#Get all list items
$ListItems = $List.Items

#Iterate through each list item
Foreach($Item in $ListItems)
{
    #Iterate through each version
    ForEach($Version in $Item.Versions) 
    {
        #Check if the status column is "Rejected"
        If($($version['Status']) -eq "Rejected")
        {
            #Update Rejected Date value of the item from version
            $Item["RejectedDate"] = $($version.Created)
            $Item.SystemUpdate()
            Write-host "ID:$($item.id), Version:$($version.VersionLabel), CreatedBy:-$($version.CreatedBy.User.DisplayName), Status:-$($version['Status'])"
            Break
        }
    }
}
This script compares each version of the list item and updates "RejectedDate" column value.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Online: Change User Permissions using PowerShell

Requirement:  Edit user permissions in SharePoint Online

How to change user permissions  in SharePoint Online?
You want to change user's permission on a particular site/library/item in SharePoint online. E.g. Once a particular project has completed and you no longer want the team member to add or edit the project's supporting documents but only view! SharePoint provides a flexible way to manage permission changes to a user or a group. Here is how to update user permissions in SharePoint online.
  • To edit site permissions for a user, Navigate to the SharePoint Online site where the user has access. Click on Settings gear and then site settings.
  • On the Site Settings page, click on "Site Permissions" link under Users and Permissions group.
  • On the site permissions page, Select the check box next to the user which you want to edit permissions. Click on "Edit User Permissions" button from the ribbon.
    edit user permissions sharepoint online
  • Select-Unselect the relevant permissions check boxes. In this case, you have to untick "Edit" and tick "Read". Click OK to save your changes.
    sharepoint online change user permissions
SharePoint online permissions will default to the highest level of security. E.g. If a user has both "Edit" and "Read" access, SharePoint considers "Edit"!

Please note, if the site or library is inheriting permissions from the parent, You may have to Stop Inheriting Permissions in order to provide unique permission to the item.

Edit user permissions in sharepoint online using PowerShell:
Lets script the above task of editing the user permissions. Remove "Edit" and add "Read" permission to the user at site level.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/marketing"
$UserAccount="i:0#.f|membership|Salaudeen@crescent.com"
$PermissionToRemove="Edit"
$PermissionToAdd="Read"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get all Users of the site
    $Users = $Ctx.Web.SiteUsers
    $Ctx.Load($Users)
    $Ctx.ExecuteQuery()
    
    #Get user accounts
    $UserAccounts =  $Users | Select -ExpandProperty LoginName

    #Check if the given user exists in the site
    If($UserAccounts -Contains $UserAccount)
    {
        #Get the User
        $User = $ctx.Web.SiteUsers.GetByLoginName($UserAccount)

        #Get Permission Levels to add and remove
        $RoleDefToAdd = $Ctx.web.RoleDefinitions.GetByName($PermissionToAdd)
        $RoleDefToRemove = $Ctx.web.RoleDefinitions.GetByName($PermissionToRemove)
        
        #Get the User's role assignment on the web
        $RoleAssignment = $Ctx.web.RoleAssignments.GetByPrincipal($User)
        
        #Add/remove permission levels to the role assignment
        $RoleAssignment.RoleDefinitionBindings.Add($RoleDefToAdd)
        $RoleAssignment.RoleDefinitionBindings.Remove($RoleDefToRemove)
        $RoleAssignment.Update()
        $Ctx.ExecuteQuery() 

        write-host  -f Green "User permissions updated Successfully!"
    }
    else
    {
        Write-host -f Yellow "User Doesn't exist in the site!"
    }
}
Catch {
    write-host -f Red "Error Updating User Permissions!" $_.Exception.Message
} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Online: Change Group Permissions using PowerShell

Requirement: SharePoint Online Change Group Permissions

How to Update permissions for a SharePoint group?
To edit group permissions in SharePoint Online, following these steps:
  • Login to your SharePoint Online site as a administrator >> On the site collection Home page, click on Settings icon >> Click Site settings.
  • On the Site Settings page, under Users and Permissions, click on Site permissions.
  • Select the check box of the group to which you want to change permissions (either to grant additional rights or to revoke existing permissions).
  • In the Modify section of the ribbon, click on "Edit User Permissions" button.
    sharepoint online edit group permissions
  • On the Edit Permissions page, select/deselect the group permission check boxes according to your requirement. You can simply tick a checkbox next to permission levels such as "Contribute" to grant permission or uncheck to remove permission from the group.
    SharePoint Online Change Group Permissions using powershell
  • Click OK to save permission changes to the group.

Now, Lets edit group permissions using PowerShell.

PowerShell to change group permissions in SharePoint Online:
For the members group of the site, lets remove "Edit" permissions and add "Contribute"
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/marketing"
$GroupName="Marketing Team Site Members"
$PermissionToRemove="Edit"
$PermissionToAdd="Contribute"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get all groups of the site
    $Groups = $Ctx.Web.SiteGroups
    $Ctx.load($Groups)
    $Ctx.ExecuteQuery()
    
    #Get Group Names
    $GroupNames =  $Groups | Select -ExpandProperty Title
    
    #Check if the given group exists
    If($GroupNames -contains $GroupName)
    {
        #Get the Group
        $Group = $ctx.Web.SiteGroups.GetByName($GroupName)

        #Get Permission Levels to add and remove
        $RoleDefToAdd = $Ctx.web.RoleDefinitions.GetByName($PermissionToAdd)
        $RoleDefToRemove = $Ctx.web.RoleDefinitions.GetByName($PermissionToRemove)
        
        #Get the Group's role assignment on the web
        $RoleAssignment = $Ctx.web.RoleAssignments.GetByPrincipal($Group)
        
        #Add/remove permission levels to the role assignment
        $RoleAssignment.RoleDefinitionBindings.Add($RoleDefToAdd)
        $RoleAssignment.RoleDefinitionBindings.Remove($RoleDefToRemove)
        $RoleAssignment.Update()
        $Ctx.ExecuteQuery()

        write-host  -f Green "User Group permissions updated Successfully!"
    }
    else
    {
        Write-host -f Yellow "Group Doesn't exist!"
    }
}
Catch {
    write-host -f Red "Error Changing Group Permissions!" $_.Exception.Message
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Online: Remove Site Collection Administrator using PowerShell

Requirement: Remove Site collection Administrator using PowerShell in SharePoint Online.

How to remove site collection administrator(s) in SharePoint Online?
Site collection administrators in SharePoint Online have full control for the entire site collection, including the root site and all of the sub-sites, lists and libraries in the site collection. To remove a site collection admin, follow these steps:
  • Login to SharePoint Online site as a SharePoint Online Administrator or Site collection Administrator
  • Click on Settings gear and then Site Settings
  • On the site settings page, click on "Site Collection Administrators" link
    SharePoint Online PowerShell to Remove Site Collection Administrator
  • Remove unwanted users from the site collection administrators and click on "OK" to save your changes.

SharePoint Online: PowerShell to Remove Site Collection Administrator
To remove a user from site collection administrators rights for a particular SharePoint Online site collection, use this PowerShell script in SharePoint Online Management Shell:
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminAccount="salaudeen@crescent.com"

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential (Get-Credential)

#Get the Site Collection
$Site = Get-SPOSite "https://crescent.sharepoint.com/sites/marketing"

#Remove user from site collection admin
Set-SPOUser -site $Site -LoginName $AdminAccount -IsSiteCollectionAdmin $False 

Remove Site Collection Admin from All Site Collections:
Lets scan all site collections and remove a particular user from site collection admin.
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/" 
$AdminAccount="salaudeen@crescent.com"

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential (Get-Credential)

#Get All Site Collections
$Sites = Get-SPOSite -Limit ALL

#Loop through each site and add site collection admin
Foreach ($Site in $Sites)
{
    Write-host "Scanning site:"$Site.Url -f Yellow
    #Get All Site Collection Administrators
    $Admins = Get-SPOUser -Site $site.Url | Where {$_.IsSiteAdmin -eq $true}

    #Iterate through each admin
    Foreach($Admin in $Admins)
    {
        #Check if the Admin Name matches
        If($Admin.LoginName -eq $AdminAccount)
        {
            #Remove Site collection Administrator
            Write-host "Removing Site Collection Admin from:"$Site.URL -f Green
            Set-SPOUser -site $Site -LoginName $AdminAccount -IsSiteCollectionAdmin $False
        }
    }
}

Remove user from Site Collection Administrator group using PowerShell - CSOM:
Other than SharePoint Online management shell, we can also use CSOM code in PowerShell to remove a site collection administrator.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/marketing"
$UserAccount="i:0#.f|membership|Salaudeen@crescent.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

$User = $Ctx.Web.EnsureUser($UserAccount)
$User.IsSiteAdmin = $False
$User.Update()
$Ctx.ExecuteQuery()

Site Collection Administrator in SharePoint Online Modern Team sites and Groups
In SharePoint Online Modern team sites & Groups Sites, "Site collection Administrators" link in hidden from UI, However you can access it by URL: https://tenant.sharepoint.com/sites/sitename/_layouts/15/mngsiteadmin.aspx and remove site collection admin or use PowerShell as given above!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, February 14, 2017

Fix for SharePoint 2016 Project Templates Missing in Visual Studio 2015

Problem: SharePoint Project Templates are missing in Visual Studio 2015!
sharepoint project templates missing in visual studio
Solution:
We need to install "Microsoft Office Developer Tools for Visual Studio 2015" for SharePoint 2016 project templates in Visual Studio 2015.
Once installed, You should see SharePoint 2016 project templates in Visual Studio 2015!
sharepoint 2016 project templates missing in visual studio 2015


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, February 11, 2017

SharePoint Online: Get All Users using PowerShell

While my another post addresses How to get all users and groups in SharePoint Online, this post aims to get all users of the SharePoint site collection.

SharePoint Online: PowerShell Get All Users of the Site Collection
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Site collection URL
$SiteURL="https://crescent.sharepoint.com"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

#Initialize the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials 

#Get all users of the site collection
$Users = $ctx.Web.SiteUsers
$ctx.Load($Users) 
$ctx.ExecuteQuery()

#Get User name and Email
$Users | ForEach-Object { Write-Host "$($_.Title) - $($_.Email)"}

PowerShell to Get All Users from All Site Collections in SharePoint Online:
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

$AdminSiteURL="https://crescent-admin.sharepoint.com/"

#Connect to SharePoint Online Admin
Write-host "Connecting to Admin Center..." -f Yellow
Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential)

Write-host "Getting All Site collections..." -f Yellow
#Get each site collection and users
$Sites = Get-SPOSite -Limit ALL

Foreach($Site in $Sites)
{
    Write-host "Getting Users from Site collection:"$Site.Url -f Yellow
    Get-SPOUser -Limit ALL -Site $Site.Url | Select DisplayName, LoginName
}

Tags: sharepoint online csom get all users, sharepoint online get all users, sharepoint online powershell get all users, sharepoint online user reports, sharepoint online users list

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Online: Create Announcement List using PowerShell

Requirement: Create Announcement List in SharePoint Online.

How to Create Announcement list in SharePoint Online?
Here is how to create announcement list in SharePoint Online:
  • Navigate to the SharePoint Online Site >> Click on Settings Gear >> Select "Add an App" 
    sharepoint online announcement list
  • From the Apps page, Click on "Announcements" Tile
    sharepoint online powershell to create announcement list
  • Provide the name to your announcement list and click on Create.
    create announcement list in sharepoint online
 This creates announcement list in SharePoint Online.

SharePoint Online: PowerShell to Create Announcement List
Here is the PowerShell CSOM script to create announcement list in SharePoint Online.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set Parameter Values
$SiteURL="https://crescent.sharepoint.com"
$ListName="Townhall"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

#Set creating data for announcement list
$CreationInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$CreationInfo.Title = $ListName
$CreationInfo.TemplateType = [int][Microsoft.SharePoint.Client.ListTemplateType]::Announcements
$CreationInfo.Description = "$ListName Announcements"

#Create Announcement in SharePoint Online
$List = $Ctx.web.Lists.Add($CreationInfo)
$Ctx.ExecuteQuery()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, February 10, 2017

SharePoint Online: Copy Attachments from One List to Another using PowerShell

Requirement: Copy Attachment from one list to another in SharePoint Online.

 PowerShell to Copy Attachment to Another List in SharePoint Online:
Had a requirement to copy attachments between SharePoint Online lists. (only attachment - Not list items!). This script gets the attachments from source list, searches the matching list item based on "Mapping Column" value and attaches list attachments to the destination list items.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Copy-Attachments()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $SourceListName,
        [Parameter(Mandatory=$true)] [string] $TargetListName,
        [Parameter(Mandatory=$false)] [string] $MappingColumn="Title"
    )    
    Try {
    #Setup Credentials to connect
    $Cred = Get-Credential
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred

    #Get the Source List & Target Lists
    $SourceList = $Ctx.Web.Lists.GetByTitle($SourceListName)
    $TargetList = $Ctx.Web.Lists.GetByTitle($TargetListName)
    
    #Get All Items
    $SourceListItems = $SourceList.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
    $TargetListItems = $TargetList.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
    $Ctx.Load($SourceListItems)
    $Ctx.Load($TargetListItems)
    $Ctx.ExecuteQuery()

    #Iterate through each list item from source
    ForEach($SourceItem in $SourceListItems)
    {
        #Get All attachments from the List Item
        $AttachmentsColl = $SourceItem.AttachmentFiles
        $Ctx.Load($AttachmentsColl)
        $Ctx.ExecuteQuery()

        #Get Matching List item in the target list
        $ListItem = $TargetListItems | Where { $_[$MappingColumn] -eq $SourceItem[$MappingColumn]}
        if($ListItem -ne $null)
        {
            #Get attachment for each list item
            ForEach($Attachment in $AttachmentsColl)
            {
                $AttachmentCreation = New-Object Microsoft.SharePoint.Client.AttachmentCreationInformation

                #Get the Source attachment
                $FileContent = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($Ctx, $Attachment.ServerRelativeUrl)
                $Buffer = New-Object byte[]($FileContent.length)
                $BytesRead = $FileContent.stream.Read($Buffer, 0, $Buffer.Length)
                $ContentStream = New-Object -TypeName System.IO.MemoryStream ($Buffer)

                $AttachmentCreation.ContentStream = $ContentStream
                $AttachmentCreation.FileName = $Attachment.FileName 
                [void]$ListItem.AttachmentFiles.Add($AttachmentCreation)
                $Ctx.ExecuteQuery()                
            }
       }
    }

    write-host  -f Green "List Attachments Copied from '$SourceListName' to '$TargetListName' !"
    }
    Catch {
        write-host -f Red "Error Copying List Attachments!" $_.Exception.Message
    } 
}

#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$SourceListName="Projects"
$TargetListName="Project Temp"

#Call the function to copy list items
Copy-Attachments -siteURL $SiteURL -SourceListName $SourceListName -TargetListName $TargetListName 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


List View Threshold in SharePoint Online - FAQs

What is List View Threshold Limit in SharePoint Online?
List View Threshold is a limit of 5000 list items in SharePoint online, which can't be exceeded!

Is it possible to Change List View Threshold in SharePoint Online?
No! we can't change list view threshold in SharePoint Online. The number 5000 is fixed and controlled by Microsoft to ensure better performance in SharePoint Online as its operates as shared tenant environment. If its SharePoint On-premises, You can change list threshold via Central Administration site: How to Increase List Threshold in SharePoint?

How to Increase List View Threshold in SharePoint Online?
Its not possible to increase threshold limit sharepoint online!

List View Lookup Threshold in SharePoint Online:
SharePoint Online has lookup column threshold of 12. (It was 8 in SharePoint on-premises - before June 2013 CU). Also, when the parent list contains more than 5000 items, then you'll get the error message: "This is a lookup column that displays data from another list that currently exceeds the List View Threshold defined by the administrator (5000)"

I've less than 8 Lookup columns, but still I'm getting Lookup threshold exceed error message. Why?
Well, other than standard lookup columns, there are few more columns in SharePoint which are considered as "Lookup"! Such as:
  • Managed metadata columns
  • Person or group columns
  • Workflow Status
  • Created by, Modified by
  •  Name ( linked to Document) , Link (Edit to edit item) , Name ( linked to Document with edit menu), type ( icon linked to document)
I've more than 5000 items in my SharePoint List. How Do I Overcome threshold Issue?
  • Set filters through "Modify list view" and limit the number of items in the view to less than 5000 to mitigate this issue. You can categorize your list items based on metadata whichever present in the list such as category, department, business function, etc.
  • Archive old list items either by moving to a new list or a folder inside the same list.
  • Try adding Indexed columns.
What's the problem when you Exceed List Threshold Limit?
When the list view threshold limit is exceeded, you'll find a warning message in list settings under as List View Threshold: The Number of items in this list exceeds the list view threshold, which is 5000 items. Tasks that cause excessive server load (such as those involving all list items) are currently prohibited." message.
list view threshold in sharepoint online
Also, when you try to filter or sort column values, you'll see "Cannot show the value of the filter. The field may not be filterable, or the number of items returned exceeds the list view threshold enforced by the administrator" message.
list view threshold sharepoint online

How to avoid list Threshold issue in CSOM?
The same threshold issue arises when you try to get all list items programmatically. Use "ListItemCollectionPosition" Property when you access large lists through CSOM code. Here is my example for reading large lists in SharePoint Online PowerShell-CSOM : How to Get All List Items from Large Lists in SharePoint Online

Here is the Microsoft article on managing large lists in SharePoint Online: Manage large lists and libraries in SharePoint

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...