Powershell:
#Get input XML
$xmlFile1 = "$dp0\SharedColumns.xml"
$col = [xml](Get-Content $xmlFile1)
$sharedcol=$col.SiteColumns.Columns.Field.Name
$FieldName = $_.Name
$myCT=$web.ContentTypes[$contentTypeName]
#Set Shared Columns
$sharedFileXMLPrefix=”"
$sharedFileXML=""
$sharedFileXMLSuffix="
”#Get input XML
$xmlFile1 = "$dp0\SharedColumns.xml"
$col = [xml](Get-Content $xmlFile1)
$sharedcol=$col.SiteColumns.Columns.Field.Name
$FieldName = $_.Name
$myCT=$web.ContentTypes[$contentTypeName]
#Set Shared Columns
$sharedFileXMLPrefix=”
$sharedFileXML=""
$sharedFileXMLSuffix="
$sharedcol | ForEach {
Write-Host $_
$id=$myCT.Fields[$_].Id
$sharedFileXML=$sharedFileXML+"
Write-Host $sharedFileXML
}
$FinalValue=$sharedFileXMLPrefix+$sharedFileXML+ $sharedFileXMLSuffix
Write-Host $FinalValue
$oXMLDocument=New-Object System.XML.XMLDocument
$ns = New-Object Xml.XmlNamespaceManager $oXMLDocument.NameTable
$ns.AddNamespace( "NamespaceURI", "http://schemas.microsoft.com/office/documentsets/sharedfields" )
$oXMLDocument.LoadXML($FinalValue);
Write-Host $oXMLDocument.ToString();
$myCT.XmlDocuments.Delete("http://schemas.microsoft.com/office/documentsets/sharedfields");
$myCT.XmlDocuments.Add($oXMLDocument);
#Set Allowed ContentType
$AllowedCTName=$col.SiteColumns.Columns.AllowedCT
Write-Host $AllowedCTName
$AllowedCT=$web.ContentTypes[$AllowedCTName]
$AllowedCTXMLPrefix=”
$AllowedCTXML=""
$AllowedCTXMLSuffix="
”
$AllowedCTid=$AllowedCT.Id
$AllowedCTXML=$AllowedCTXML+"
Write-Host $AllowedCTXML
$AllowedCTFinalValue=$AllowedCTXMLPrefix+$AllowedCTXML+ $AllowedCTXMLSuffix
Write-Host $AllowedCTFinalValue
$AllowedCTXML=New-Object System.XML.XMLDocument
$ns1 = New-Object Xml.XmlNamespaceManager $AllowedCTXML.NameTable
$ns1.AddNamespace( "NamespaceURI", "http://schemas.microsoft.com/office/documentsets/allowedcontenttypes" )
$AllowedCTXML.LoadXML($AllowedCTFinalValue);
Write-Host $AllowedCTFinalValue.ToString();
$myCT.XmlDocuments.Delete("http://schemas.microsoft.com/office/documentsets/allowedcontenttypes");
$myCT.XmlDocuments.Add($AllowedCTFinalValue);
$myCT.Update();
XML:
This comment has been removed by the author.
ReplyDeleteGet the best SharePoint Consulting
ReplyDelete