标签:
通过PowerShell创建SharePoint Site Collection,代码如下:
Add-PSSnapin microsoft.sharepoint.powershell function CreateTeamSite() { $webApps = Get-SPWebApplication $webAppsUrl = $webApps.Url if($webApps.count -eq 1) { Write-Host "You have only one web application:" Write-Host $webApps.Url $choice = Read-Host "Do you want to create a site collection under this web application? Type ‘y‘ to create.‘" if($choice -eq "y") { $siteTitle = Read-Host "Enter the site collection‘s title:" $siteUrl = $webAppsUrl+"sites/"+$siteTitle Write-Host "Choose the site collecion‘s template:" Write-Host "[1].填写你的模板名." Write-Host "[2].填写你的模板名." Write-Host "[3].填写你的模板名." $choice = Read-Host "Enter the number to choose:" SwitchSiteTemplateAndCreateSite $choice $siteUrl } } else { Write-Host "Choose the web application:" for($i=0;$i -le $webApps.count;$i++) { Write-Host "[" + $i + "]." + $webApps[$i].Url } $choice = Read-Host "Enter the number to choose:" $siteTitle = Read-Host "Enter the site collection‘s title:" $siteUrl = $webApps[$choice].Url + "sites/"+$siteTitle Write-Host "Choose the site collecion‘s template:" Write-Host "[1].填写你的模板名." Write-Host "[2].填写你的模板名." Write-Host "[3].填写你的模板名." $choice = Read-Host "Enter the number to choose:" SwitchSiteTemplateAndCreateSite $choice $siteUrl } } function SwitchSiteTemplateAndCreateSite($choice,$siteUrl) { switch($choice) { 1 {$template = "填写你的模板ID"} 2 {$template = "填写你的模板ID"} 3 {$template = "填写你的模板ID"} } if(($template -ne "填写你的模板ID") -and ($template -ne "填写你的模板ID") -and ($template -ne "填写你的模板ID")) { $choice = Read-Host "Please enter the correct number." SwitchSiteTemplateAndCreateSite $choice $siteUrl }else { Write-Host "Site collection creating..." New-SPSite -Url $siteUrl -OwnerAlias "填写你的UserName" -Language 1033 -Template $template Write-Host "Site collection created successfully." } } CreateTeamSite
中文的部分可替换(非中文的部分部分内容也可以进行替换,看个人需求。),switch语句中可以扩展模板ID(相应在提示填写模板名处也要做相应的添加)。日常工作中,选择几个常用的模板ID和模板名填进去即可,UserName填写你常用的那个就可以,最好是所有环境都通用的user(这样就不会因为换了域就找不到用户了),不用填写域,因为SharePoint支持模糊搜索,会自动将你输入的名字进行匹配,比如你输入Tylan,如果在SharePoint中存在该用户的话,SharePoint在check用户名时会自动在其前面加上Domain,像这样:“Domain\Tylan”。
其实写成脚本就是为了方便日常工作,节省时间,具体要把哪些地方设成变量哪些地方进行硬编码可以根据工作需要而变,仍然是以提高工作效率为目的。如果是长久的项目,为了推广使用,做个窗体工具也未尝不可,关键是看有没有这个必要。
通过PowerShell创建SharePoint Site Collection。
标签:
原文地址:http://www.cnblogs.com/LanTianYou/p/4817194.html