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
 Happy Coding.
Sathish Nadarajan.

 
  
 
Leave a comment