欢迎光临寺界 领略名寺魅力

experience the african style

领略非洲风情 体会彩色国度

使用powershell导出sharepoint列表数据-凯发网址

凯发网址-凯发游戏下载    正成    行业资讯    使用powershell导出sharepoint列表数据

适用版本

  • sharepoint 2010

  • sharepoint 2013

介绍

导出列表数据到csv文件,以便借助excel等工具进行数据分析。sharepoint在ui上提供了列表数据导出到excel的功能,但是受数据量,超时时间等影响(目前没有找到官方确认说法,继续搜寻中)。使用此脚本可以避免这样的风险,而且还可以扩展代码进行导出前一定业务逻辑的处理。

脚本

 
 
############################################################
# shuishan s2 export list data to csv file.
# version: 0.0.0.1
# 12/19/2014
# http://www.shuishan-tech.com
# author: yangliu@上海水杉网络科技有限公司
# description:
# 导出列表数据到csv文件,以便借助excel等工具进行数据分析。
# sharepoint在ui上提供了列表数据导出到excel的功能,但是受数据量,超时时间等影响(目前没有找到官方确认说法,继续搜寻中)。
# 使用此脚本可以避免这样的风险,而且还可以扩展代码进行导出前一定业务逻辑的处理。
############################################################
 
#判断当前上下文环境中是否装在了sharepoint的powershell环境,如果没有装载,则装载到当前运行环境。
$snapin = get-pssnapin | where-object {$_.name -eq 'microsoft.sharepoint.powershell'}
if($snapin -eq $null){
write-output -inputobject "loading sharepoint powershell snapin"
try
{
add-pssnapin "microsoft.sharepoint.powershell"
write-output -inputobject "loaded sharepoint powershell snapin"
}
catch
{
$(throw "there was an error loading sharepoint powershell snapin")
exit
}
}
 
#获取web对象, 根据需要替换为自己的网站地址。
$web = get-spweb http://demo.shuishan-tech.com
#获取list对象,根据需要替换为自己的列表名称。
$list = $web.lists["sso_user"]
#获取列表所有数据。
$list.getitems() |
#在管道中循环获取到得列表数据。
foreach-object{
#构建psobject。
$obj = new-object psobject;
#把每一行splistitem上的数据注入到构建的psobject对象实例中,如果是splistitem内建字段,可以使用 $_.id 这样的格式获取。
add-member -membertype noteproperty -inputobject $obj -name "id" -value $_.id;
add-member -membertype noteproperty -inputobject $obj -name "title" -value $_.title;
add-member -membertype noteproperty -inputobject $obj -name "created" -value $_.craeted;
add-member -membertype noteproperty -inputobject $obj -name "modified" -value $_.modified;
#也可以获取自定义字段,需要使用 $_["fieldname"] 这种方式获取。
add-member -membertype noteproperty -inputobject $obj -name "customfield" -value $_["customfield"];
################
#提示:可以在这里注入自己的业务逻辑,对splistitem获取到得数据进行格式化,然后注入到对象中。
################
 
#输出包含数据的对象。
$obj
} |
#在下一个管道中输出对象中的数据到csv文件,如果包含中文字符,需要使用 -encoding utf8的属性。
export-csv c:\list.csv -encoding utf8
2015年1月14日 12:07
浏览量:0
网站地图