Export Sharepoint list to XML file
We had problems to export list items with localized names (list name, column names). We should use column names from schema.xml.
.
#input parameter
$siteUrl="https://td_sp_ui/portal"
$exportFile= "C:\InstallFolder\glo.xml"
add-pssnapin microsoft.sharepoint.powershell
# create a template XML to hold data
$template = @'
<glossary>
<point>
<term></term>
<description></description>
<languageindex></languageindex>
</point>
</glossary>
'@
$template | Out-File $exportFile -encoding UTF8
# load template into XML object
$xml = New-Object xml
$xml.Load($exportFile)
# grab template point
$newpoint = (@($xml.glossary.point)[0]).Clone()
#get glossary list
$subsiteUrl=$siteUrl + "/Helpdesk"
$web=get-spweb $subsiteUrl
$glossaryUrl=$subsiteUrl + "/Lists/Glossary-ListInstance1"
$glo=$web.GetList($subsiteUrl + "/Lists/Glossary-ListInstance1")
foreach($item in $glo.items)
{
# use template to add point to xml
$newpoint = $newpoint.clone()
$newpoint.term = $item.item("Title")
$newpoint.Description = $item.item("GBP-Glossary-Description")
$newpoint.languageindex = $item.item("avd-GBP-PageLanguage").substring(0,1)
$xml.glossary.AppendChild($newpoint) > $null
}
$web.dispose()
# remove term with undefined name (remove template)
$xml.glossary.point |
Where-Object { $_.Term -eq "" } |
ForEach-Object { [void]$xml.glossary.RemoveChild($_)
}# save xml to file
$xml.Save($exportFile)
# play with results
$xml.glossary.point | Sort-Object term | Format-Table term, description, languageindex
& $exportFile