通过PowerShell创建SharePoint Site Collection,代码如下:

Add-PSSnapin microsoft.sharepoint.powershell
function CreateTeamSite()
{
$webApps = Get-SPWebApplication
$webAppsUrl = $webApps.Url
if($webApps.count -eq )
{
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].Template1."
Write-Host "[2].Template2."
Write-Host "[3].Template3."
$choice = Read-Host "Enter the number to choose"
SwitchSiteTemplateAndCreateSite $choice $siteUrl
$choice = Read-Host "Type 'y' to continue"
if($choice -eq 'y')
{
CreateTeamSite
}
}
}
else
{
Write-Host "Choose the web application:"
for($i=;$i -le $webApps.count-;$i++)
{
$tip = "[" + $i + "]." + $webApps[$i].Url
Write-Host $tip
}
$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].Template1."
Write-Host "[2].Template2."
Write-Host "[3].Template3."
$choice = Read-Host "Enter the number to choose"
SwitchSiteTemplateAndCreateSite $choice $siteUrl
$choice = Read-Host "Type 'y' to continue"
if($choice -eq 'y')
{
CreateTeamSite
}
}
}
function SwitchSiteTemplateAndCreateSite($choice,$siteUrl)
{
switch($choice)
{
{$template = "Template1ID"}
{$template = "Template2ID"}
{$template = "Template3ID"}
}
if(($template -ne "Template1ID") -and ($template -ne "Template2ID") -and ($template -ne "Template3ID"))
{
$choice = Read-Host "Please enter the correct number."
SwitchSiteTemplateAndCreateSite $choice $siteUrl
}else
{
Write-Host "Site collection creating..."
New-SPSite -Url $siteUrl -OwnerAlias "Administrator" -Language -Template $template
Write-Host "Site collection created successfully."
}
}
CreateTeamSite

文中Template和TemplateID可替换(其他部分也可以进行替换,看个人需求。),switch语句中可以扩展模板ID(相应在提示填写模板名处也要做相应的添加)。日常工作中,选择几个常用的模板ID和模板名填进去即可,UserName填写你常用的那个就可以,最好是所有环境都通用的user(这样就不会因为换了域就找不到用户了),不用填写域,因为SharePoint支持模糊搜索,会自动将你输入的名字进行匹配,比如你输入Tylan,如果在SharePoint中存在该用户的话,SharePoint在check用户名时会自动在其前面加上Domain,像这样:“Domain\Tylan”。

其实写成脚本就是为了方便日常工作,节省时间,具体要把哪些地方设成变量哪些地方进行硬编码可以根据工作需要而变,仍然是以提高工作效率为目的。如果是长久的项目,为了推广使用,做个窗体工具也未尝不可,关键是看有没有这个必要。

SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection的更多相关文章

  1. SharePoint自动化系列——通过PowerShell创建SharePoint Web

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  2. SharePoint自动化系列——通过PowerShell创建SharePoint Lists

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  3. SharePoint自动化系列——通过PowerShell创建SharePoint List Items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

  4. SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好. ...

  5. SharePoint自动化系列——Upload files to SharePoint library using PowerShell.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...

  6. 使用PowerShell 创建SharePoint 站点

    使用PowerShell 创建SharePoint 站点         在SharePoint开发中,你应该学会使用PowerShell管理SharePoint网站.SharePoint Manag ...

  7. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  8. SharePoint自动化系列——Error features自动deactivate

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...

  9. SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...

随机推荐

  1. jQuery知识集锦

      CreateTime--2017年2月16日14:00:22Author:MarydonjQuery知识集锦1.empty()与remove()的区别 <select id="ty ...

  2. SwaggerUI+SpringMVC——构建RestFul API的可视化界面

    今天给大家介绍一款工具,这个工具眼下可预见的优点是:自己主动维护最新的接口文档. 我们都知道,接口文档是非常重要的,可是随着代码的不断更新,文档却非常难持续跟着更新,今天要介绍的工具,完美的攻克了这个 ...

  3. 关于vsftpd的refusing to run with writable root inside chroot()问题

    今天在上班帮测试的同事搭建ftp服务器时出现的一个问题 服务搭建完成后连接时报这个错误: refusing to run with writable root inside chroot() 查了资料 ...

  4. free -m 内存

    查看内存及交换swap分区大小及使用率 man  free NAME free - Display amount of free and used memory in the system SYNOP ...

  5. Java IO 要点总结

    Java 流在处理上分为字符流和字节流.字符流处理的单元为 2 个字节的 Unicode 字符,分别操作字符.字符数组或字符串,而字节流处理单元为 1 个字节,操作字节和字节数组. Java 内用 U ...

  6. Spring配置文件头信息

    代码如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...

  7. HDUOJ----Eddy's research I

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. POJ 3691 DNA Sequence (AC自动机 + 矩阵 有bug,待修改)

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9889   Accepted: 3712 Desc ...

  9. POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  10. python学习笔记——

    python线程的GIL GIL (全局解释器锁)python --- > 支持多线程 ----> 同步和互斥 --->加锁 --->解释器加锁 ————> 解释器同一时 ...