导航

在PowerShell中操作SharePoint对象

Posted on 2010-05-19 17:58  FryFish  阅读(216)  评论(0编辑  收藏  举报

1. 用PowerShell创建一个SharePoint内容对象
创建一个自定义列表:
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://inno"); $OpenWeb = $SpSite.OpenWeb(); $TemplateType = $OpenWeb.ListTemplates["自定义列表"]; $OpenWeb.Lists.Add("My Custom List2","Description Of My Custom List",$TemplateType); $OpenWeb.Dispose(); $SPSite.Dispose()

2. 用PowerShell列出站点所有Content模板
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://inno"); $OpenWeb = $SpSite.OpenWeb(); $OpenWeb.ListTemplates | Select Name, Description; $OpenWeb.Dispose(); $SPSite.Dispose()

3. 如何用PowerShell导出/备份SharePoint站点
You need something like this:
Get-SPWeb -site http://sp2010  | ForEach-Object { $filename = $_.Url.replace("http://","").replace("-","--").replace("/","-") + ".export" ; Write-Host export-spweb $_ -path $filename}
That will walk through all the webs under sp2010, remove the "http://" at the beginning, replace all the dashes with doubledashes, and the slashes with dashes. Then exports them. That way something like http://sp2010/sites/test/foo-bar will be savesd as sites-test-foo--bar.export.
Oh, and you'll have to remove the "write-host" for it to actually work. I put that in as a safety measure. :)