Created
August 14, 2016 18:08
-
-
Save arjancornelissen/5ec48b589844209dbf1c6bef3373bb89 to your computer and use it in GitHub Desktop.
Term store import with Office Dev PnP Full
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function writeTermLine($csvlines, $csvfile) | |
| { | |
| foreach($csvline in $csvlines) | |
| { | |
| $xmlWriter.WriteStartElement("pnp:Term") | |
| $xmlWriter.WriteAttributeString("Name",$csvline.Name) | |
| $xmlWriter.WriteAttributeString("Language","1033") | |
| $xmlWriter.WriteStartElement("pnp:CustomProperties") | |
| #properties | |
| $xmlWriter.WriteStartElement("pnp:Property") | |
| $xmlWriter.WriteAttributeString("Key","CompanyID") | |
| $xmlWriter.WriteAttributeString("Value",$csvline.ID) | |
| #end pnp:CustomProperties | |
| $xmlWriter.WriteEndElement() | |
| #properties | |
| $xmlWriter.WriteStartElement("pnp:Property") | |
| $xmlWriter.WriteAttributeString("Key","ParentCompanyID") | |
| $xmlWriter.WriteAttributeString("Value",$csvline.parentID) | |
| #end pnp:CustomProperties | |
| $xmlWriter.WriteEndElement() | |
| #properties | |
| $xmlWriter.WriteStartElement("pnp:Property") | |
| $xmlWriter.WriteAttributeString("Key","Sector") | |
| $xmlWriter.WriteAttributeString("Value",$csvline.Sector) | |
| #end pnp:CustomProperties | |
| $xmlWriter.WriteEndElement() | |
| #end pnp:CustomProperties | |
| $xmlWriter.WriteEndElement() | |
| $Companyid = $csvline.ID | |
| #check if item has childrem | |
| $csvitems = $csvfile | where {$_.parentID -eq $Companyid} | |
| if($csvitems.Count -gt 0) | |
| { | |
| writeTermLine $csvitems $csvfile | |
| } | |
| #end pnp:Term | |
| $xmlWriter.WriteEndElement() | |
| } | |
| } | |
| $csv = Import-Csv -Delimiter `t -Path "CompanyList.txt" | |
| $filePath = "CompanyList.xml" | |
| $xmlencoding = New-Object System.Text.UTF8Encoding($false); | |
| $xmlWriter = New-Object System.Xml.XmlTextWriter($filePath,$xmlencoding) | |
| $xmlWriter.Formatting = "Indented" | |
| $xmlWriter.Indentation = 4 | |
| $xmlWriter.WriteStartDocument(); | |
| $xmlWriter.WriteStartElement("pnp:TermGroups") | |
| $xmlWriter.WriteStartElement("pnp:TermGroup") | |
| $xmlWriter.WriteAttributeString("Name","Corporate") | |
| $xmlWriter.WriteAttributeString("ID","c20c3140-29a4-4ca0-92a8-e353cca620bd") | |
| $xmlWriter.WriteAttributeString("Description"," ") | |
| #start termset | |
| $xmlWriter.WriteStartElement("pnp:TermSets") | |
| $xmlWriter.WriteStartElement("pnp:TermSet") | |
| $xmlWriter.WriteAttributeString("Name","Company") | |
| $xmlWriter.WriteAttributeString("Description","Company structure") | |
| $xmlWriter.WriteAttributeString("Language","1033") | |
| $xmlWriter.WriteStartElement("pnp:Terms") | |
| #foreach row pnp:Term | |
| $rooterm = $csv | Where { $_.ID -eq "1"} | |
| writeTermLine $rooterm $csv | |
| #end pnp:Terms | |
| $xmlWriter.WriteEndElement() | |
| #end pnp:TermSet | |
| $xmlWriter.WriteEndElement() | |
| #end pnp:TermSets | |
| $xmlWriter.WriteEndElement() | |
| #end pnp:TermGroup | |
| $xmlWriter.WriteEndElement() | |
| #end pnp:TermGroup | |
| $xmlWriter.WriteEndElement() | |
| #end document | |
| $xmlWriter.WriteEndDocument() | |
| $xmlWriter.Flush() | |
| $xmlWriter.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment