将Sharepoint列表导出为CSV,然后创建工作XML文件
我正在尝试使用PowerShell导出SharePoint 365联机列表。 导出结果应转到CSV。从那里,我想获取信息并将其合并到一个XML目录列表中 应直接列出输出 接待 200 用户1 201 用户2 202 我的SharePoint列表包含所有相关信息名称和分机号码。 普通电话是用户和分机号码 然后,需要将其自动化,以便每天运行 到目前为止,我掌握的代码是: 在Microsoft.SharePoint.PowerShell中添加PSSnapin-ErrorAction SilentlyContinue $LiveCred=获取凭证 $web=获取SPWeb-标识https://*.sharepoint.com/IT/Lists/VOIP%20extensions/ $list=$web.Lists[Voip%20扩展名] $ListItemCollection=@ $list.Items | Where Object{$_[Status]-eq-In-Progress}| foreach{ $ExportItem=新对象PSObject $ExportItem |添加成员-成员类型NoteProperty-名称Wxt-值$\uext[Ext] $ExportItem |添加成员-成员类型NoteProperty-名称-值$(名称) $ListItemCollection+=$ExportItem } $ListItemCollection |导出Csv c:\Phonelist.txt-NoTypeInformation将Sharepoint列表导出为CSV,然后创建工作XML文件,xml,powershell,csv,Xml,Powershell,Csv,我正在尝试使用PowerShell导出SharePoint 365联机列表。 导出结果应转到CSV。从那里,我想获取信息并将其合并到一个XML目录列表中 应直接列出输出 接待 200 用户1 201 用户2 202 我的SharePoint列表包含所有相关信息名称和分机号码。 普通电话是用户和分机号码 然后,需要将其自动化,以便每天运行 到目前为止,我掌握的代码是: 在Microsoft.SharePoint.PowerShell中添加PSSnapin-ErrorAction SilentlyC
要将数据转换为XML,请使用ConvertTo-XML cmdlet 另外,我将更改$ListItemCollection变量中收集数据的方式,以避免使用数组连接$ListItemCollection+=$ExportItem,如下所示:
$ListItemCollection = $list.Items | Where-Object { $_["Status"] -eq "In Progress"} | ForEach-Object {
[PsCustomObject]@{
"Wxt" = $_["Ext"]
"Name" = $_["Name"]
}
}
或使用XmlTextWriter类自定义XML:
# Set The Formatting
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
# Set the File Name Create The Document
$XmlWriter = [System.XML.XmlWriter]::Create("D:\test.xml", $xmlsettings)
# Write the XML Decleration and set the XSL
$xmlWriter.WriteStartDocument()
# Start the Root Element
$xmlWriter.WriteStartElement("YeastarIPPhoneDirectory")
# write the data
$ListItemCollection | ForEach-Object {
$xmlWriter.WriteStartElement("DirectoryEntry")
$xmlWriter.WriteElementString("Name", $_.Name)
$xmlWriter.WriteElementString("Telephone", $_.Wxt)
$xmlWriter.WriteEndElement() # End <DirectoryEntry>
}
$xmlWriter.WriteEndElement() # End <YeastarIPPhoneDirectory>
# End, Finalize and close the XML Document
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
这将创建一个xml:
希望这有帮助请告诉我们您的代码目前成功或失败的地方。您正在寻找的是什么?当前代码导出到纯txt或csv,两者都可以,但我需要从该csv创建一个xml文件以导入:为什么要将数据导出到csv,然后从该csv创建xml,而不是直接创建xml?另外,由于CSV导出代码显然正在工作,请显示不工作的XML转换代码,以便我们提供帮助。我们没有收到您的消息。。作为新手,您可能不知道这一点,但习惯于单击✓ 在左边。这将帮助其他有类似问题的人更容易地找到它。
# Set The Formatting
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
# Set the File Name Create The Document
$XmlWriter = [System.XML.XmlWriter]::Create("D:\test.xml", $xmlsettings)
# Write the XML Decleration and set the XSL
$xmlWriter.WriteStartDocument()
# Start the Root Element
$xmlWriter.WriteStartElement("YeastarIPPhoneDirectory")
# write the data
$ListItemCollection | ForEach-Object {
$xmlWriter.WriteStartElement("DirectoryEntry")
$xmlWriter.WriteElementString("Name", $_.Name)
$xmlWriter.WriteElementString("Telephone", $_.Wxt)
$xmlWriter.WriteEndElement() # End <DirectoryEntry>
}
$xmlWriter.WriteEndElement() # End <YeastarIPPhoneDirectory>
# End, Finalize and close the XML Document
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
<?xml version="1.0" encoding="utf-8"?>
<YeastarIPPhoneDirectory>
<DirectoryEntry>
<Name>Reception</Name>
<Telephone>200</Telephone>
</DirectoryEntry>
<DirectoryEntry>
<Name>User1</Name>
<Telephone>201</Telephone>
</DirectoryEntry>
<DirectoryEntry>
<Name>User2</Name>
<Telephone>202</Telephone>
</DirectoryEntry>
</YeastarIPPhoneDirectory>