Créer un site internet

Set Content Type Field Property

fredericdietrich By On 22/10/2018

In Powershell

param([string]$webUrl="http://spdev", [string]$contentTypeName="myContenttype", [string]$fieldName="myTitle", [boolean]$required=$true)
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
clear
$web = Get-SPWeb $webUrl
$ct = $web.ContentTypes[$contentTypeName];
$oldSealedValue = $ct.Sealed;
Write-Host "content type Sealed Property $($ct.Sealed)"
if($ct.Sealed)
{
$ct.Sealed = $false;
}
$field = $ct.FieldLinks[$fieldName];
$field.Required = $required;
Write-Host "set field $($fieldName) Required $($ct.Required)"
 
if($oldSealedValue)
{
$ct.Sealed = $true;
}
$ct.Update($true);
$web.Update();
$web.Dispose();
get script
 

powershell Sharepoint

  • 1 vote. Average rating: 5 / 5.