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


Sathish Nadarajan
SharePoint MVP
Published On :   31 Mar 2015
Visit Count
Today :  5    Total :   10072
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Forms App