$name =
"qui ci va l'internal name del campo"
$url =
"qui ci va l'url della sitecollection"
Write-Host ("Remove
Version flag from '{0}' in '{1}'" -f
$name,
$url)
$web =
Get-SPWeb $url
$web =
$web.site.RootWeb
$field =
$web.Fields.GetFieldByInternalName($name)
if (!$field) {
Write-Host ">
Can't find field!" -ForegroundColor:Red
break
}
[xml]$xml =
$field.SchemaXml
$contenttypenames =
$web.ContentTypes
| ? { $_.FieldLinks
| ? { $_.Id -eq $field.ID } } | ? { $_.Parent.Fields.ContainsFieldWithStaticName($field.InternalName)
-eq $false
} | % { Write-Output $_.Name }
$contenttypenames |
% {
$contenttypename = $_
write-host (">
Remove field link from {0}..." -f
$contenttypename) -ForegroundColor:Green
$ct =
$web.ContentTypes[$contenttypename]
$ct.FieldLinks.Delete($name)
$ct.UpdateIncludingSealedAndReadOnly($true)
}
$field =
$web.Fields.GetFieldByInternalName($name)
if ($field)
{
Write-Host ">
Deleting existing field..." -ForegroundColor:Green
$web.fields.Delete($name)
}
Write-Host ">
Adding field (version removed)..." -ForegroundColor:Green
$xml.Field.RemoveAttribute("Version")
$web.Fields.AddFieldAsXml($xml.OuterXml)
| Out-Null
$contenttypenames |
% {
$contenttypename = $_
Write-Host (">
Adding field link to {0}..." -f
$contenttypename) -ForegroundColor:Green
$field =
$web.Fields.GetFieldByInternalName($name)
$fieldlink =
New-Object Microsoft.SharePoint.SPFieldLink($field)
$ct.FieldLinks.Add($fieldlink)
$ct.Update($true)
}
Nessun commento:
Posta un commento