使用Management Shell从SharePoint 2010列表中导出数据

We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Data and save it in a csv file.  In Part2, I will explain how to schedule it on a periodic basis.  

我们需要将数据从SharePoint 2010客户列表中提取到CSV文件中,然后将CSV文件放入网络上的目录中,以便AS400系统可以使用该文件。 我将在第1部分中分享如何提取数据并将其保存在csv文件中。 在第2部分中,我将解释如何定期安排它。

After some research I found Roi Kolbinger's blog "I Will Share my Point: Export SharePoint 2010 List to Excel with PowerShell.  The problem with this is that it will only extract the Title field.  I was able to create a PowerShell script to extract the data using Roi's script as the base for my script and with a little help from a developer, named Miguel Wood,  who told me "Yes.  The .Items will only export the Title column.  To export the list, try creating and using a PSObject."  

经过研究后,我发现Roi Kolbinger的博客“我将分享我的观点:使用PowerShell将SharePoint 2010列表导出到Excel。问题是它只会提取标题字段。我能够创建一个PowerShell脚本来提取数据。使用Roi的脚本作为我脚本的基础,并且在名为Miguel Wood的开发人员的帮助下,他对我说:“是的。 .Items将仅导出“标题”列。 要导出列表,请尝试创建并使用PSObject。”

Now that we have some background information, let’s create a SharePoint Management Shell script to extract the data from a SharePoint 2010 List and into a csv file.

现在我们有了一些背景信息,让我们创建一个SharePoint Management Shell脚本,以从SharePoint 2010列表中提取数据并提取到csv文件中。

1.  Open notepad and paste the following code customizing it for your environment.

1.打开记事本并粘贴以下代码,以针对您的环境对其进行自定义。

$MyWeb = Get-SPWeb "http://sitename"

$ MyWeb = Get-SPWeb“ http:// sitename

$MyList = $MyWeb.Lists["ListName"]

$ MyList = $ MyWeb.Lists [“ ListName”]

$exportlist = @()

$ exportlist = @()

$Mylist.Items | foreach {

$ Mylist.Items | foreach {

$obj = New-Object PSObject -Property @{

$ obj =新对象PSObject-属性@ {

            “Column1” = $_["Column Name in SharePoint"]

“ Column1” = $ _ [“ SharePoint中的列名”]

           "Column2" = $_["Column Name in SharePoint"]                  

“ Column2” = $ _ [“ SharePoint中的列名”]

}

}

$exportlist += $obj

$ exportlist + = $ obj

$exportlist | Export-Csv -path 'C:\FilePath\Filename.csv'

$ exportlist | Export-Csv -path'C:\ FilePath \ Filename.csv'

}

}

*Notes:   Http://sitename is the url to the site where the list is located and ListName is the name of the List that contains the data you would like to extract.

*注意: Http:// sitename是列表所在站点的url,而ListName是包含您要提取的数据的列表的名称。

Column1 and Column2 are the names of the columns you want to be named in the CSV file.  Column Name in SharePoint is the actual column named stored in the SharePoint Database. For instance if you renamed the Title column to Name, your code should resemble the following:

Column1和Column2是要在CSV文件中命名的列的名称。 SharePoint中的列名是存储在SharePoint数据库中的实际名称。 例如,如果您将“标题”列重命名为“名称”,则您的代码应类似于以下内容:

“Name” =$_[“Title”}

“名称” = $ _ [“标题”}

Export-Csv – path is the location you want the script to save the file.

Export-Csv –路径是您希望脚本保存文件的位置。

2.  After you have made the corrections/customizations Save the file with extension ps1.  IE:  Export.ps1.

2.进行更正/自定义之后 保存扩展名为ps1的文件。 IE:Export.ps1。

3.  Place or copy the file to a drive located on the SharePoint Server you will run the script.  We utilize our Application Server.

3.将文件放置或复制到位于SharePoint Server上的驱动器中,您将运行脚本。 我们利用我们的应用服务器。

4.  Now that we have created the script, manually run it to test the file.  RDP to the server, open a SharePoint Management Shell prompt, go to the directory where you saved the file and run the following command: .\Filename.ps1

4.现在我们已经创建了脚本,请手动运行它以测试文件。 RDP到服务器,打开SharePoint命令行管理程序提示符,转到保存文件的目录,然后运行以下命令:。\ Filename.ps1

Now that you know how to extract data from a SharePoint 2010 list using SharePoint Management Shell, you can also create a scheduled task to run the file using the Windows Task Scheduler.  I will explain how you accomplish this in Part 2. Coming Soon I hope.

既然您知道如何使用SharePoint Management Shell从SharePoint 2010列表中提取数据,您还可以创建计划任务以使用Windows Task Scheduler运行文件。 我将在第2部分中解释您如何完成此任务。希望很快。

References:  

参考文献:

Reference 1:  Roi Kolbinger - I Will Share my Point: Export SharePoint 2010 List to Excel with PowerShell (http://iwillsharemypoint.blogspot.com/2011/02/export-sharepoint-2010-list-to-excel.html)

参考资料1:Roi Kolbinger-我将分享我的观点:使用PowerShell将SharePoint 2010列表导出到Excel( http://iwillsharemypoint.blogspot.com/2011/02/export-sharepoint-2010-list-to-excel.html

Reference 2:  Miguel Wood - Developer

参考2:Miguel Wood-开发人员

Thanks,

谢谢,

Eldrick

埃尔德里克

翻译自: https://www.experts-exchange.com/articles/9182/Export-data-from-SharePoint-2010-List-using-Management-Shell.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值