How to Update a Site Column as Mandatory in SharePoint 2013 using PowerShell

Sathish Nadarajan
 
Solution Architect
March 31, 2015
 
Rate this article
[Total: 0    Average: 0/5]
 
Views
14199

In this article, let us see, how to make a Site Column as Mandatory in SharePoint 2013 using PowerShell.

The script is straight forward and the same has been uploaded in the below Download Link as well. Hence, there is nothing much to explain about the requirement / script.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".\MakeContentAuthorOwnerMandatoryInProdKnowSheet-$LogTime.rtf"
 
 cls
 
 start-transcript $logfile
 
 # Add SharePoint PowerShell Snapin
 
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
     Add-PSSnapin Microsoft.SharePoint.Powershell
 }
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
 function MakeContentAuthorOwnerMandatoryInProdKnowSheet([string]$siteUrl, [string]$WebName, [string]$ListName, [string]$SiteColumnInternalName) {
   
     $site = Get-SPSite $siteUrl
 
     if($WebName -eq "")
     {
         $web = $site.RootWeb
     }
     else
     {
         $web = $site.AllWebs[$WebName]
     }
     
 
     $list = $web.Lists[$ListName]
 
     $field = $list.Fields.getFieldbyInternalName($SiteColumnInternalName)
     $field.Required = $true
     $field.Update()
     $list.Update()
     $web.Dispose()
     $site.Dispose()
     Write-Host "Updated the site column" $SiteColumnInternalName " as mandatory" -ForegroundColor Green
 }
 
 
  
 
 
 ##########################################################################################################################
 $csvfile = $scriptbase + "\" + "01.Input.csv"
 
 import-csv $csvfile | where {
 MakeContentAuthorOwnerMandatoryInProdKnowSheet $_.SiteUrl $_.WebName $_.ListName $_.SiteColumnInternalName 
 
 
 }
 
 stop-transcript
 

DOWNLOAD SCRIPT HERE

Happy Coding.

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
[Total: 0    Average: 0/5]
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment