Monday, September 8, 2014

SharePoint 2013 - Shared Column / fields and allowed contenttypes setup - powershell

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="

                 
                       $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:



 
   
 

2 comments:

  1. Success is a choice not a dream. So, work hard for it and always be open-minded. Visit my site for more information. Have a good day and keep on moving forward for that success.

    triciajoy.com

    www.triciajoy.com

    ReplyDelete
  2. I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


    edupdf.org

    ReplyDelete