SharePoint自动化系列——通过PowerShell创建SharePoint Site Collection
通过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的更多相关文章
- SharePoint自动化系列——通过PowerShell创建SharePoint Web
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint Lists
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell创建SharePoint List Items
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...
- SharePoint自动化系列——通过PowerShell在SharePoint中批量做数据
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell是基于.NET的一门脚本语言,对于SharePoint一些日常操作支持的很好. ...
- SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...
- 使用PowerShell 创建SharePoint 站点
使用PowerShell 创建SharePoint 站点 在SharePoint开发中,你应该学会使用PowerShell管理SharePoint网站.SharePoint Manag ...
- SharePoint自动化系列——Site/Web/List级别的导航菜单
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...
- SharePoint自动化系列——Error features自动deactivate
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...
- SharePoint自动化系列——Solution auto-redeploy using Selenium(C#)
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 本来的想法是做一个可以自动卸载并且部署新solution到SharePoint farm的tool ...
随机推荐
- EXCEPTION-IBATIS
CreateTime--2016年8月23日08:44:03Author:Marydonibatis的sqlMap的xml文件配置出现的异常信息及解决方案 声明:异常类文章主要是记录了我遇到的异常 ...
- C语言第一个例子hello world
1.用文本编辑器编辑代码如下,然后保存为hello.c文件 #include <stdio.h> int main(void){ printf("hello world" ...
- 如何使用jmeter来实现更大批量的并发的解决方案
近期在用JMeter进行负载测试的 时候,发现使用单台机器模拟测试超过比如500个进程的并发就有些力不从心或者说不能如实的反应实际情况,在执行的过程中,JMeter自身会自动关闭, 要解决这个问题,则 ...
- samba温故知新
SAMBA服务器可以实现Windows主机和Linux主机共享资源互访的功能,即在Windows下可以通过网上邻居访问Linux操作系统中SAMBA服务器共享的文件夹,当然,Linux操作系统之间同样 ...
- JavaScript原生实现《贪吃蛇》
概述 JavaScript原生实现<贪吃蛇>,每吃掉一个食物,蛇的身体会变长,食物会重新换位置. 详细 代码下载:http://www.demodashi.com/demo/10728.h ...
- Java IO:BIO和NIO差别及各自应用场景
转载请注明出处:jiq•钦's technical Blog - 季义钦 引言 BIO和NIO是两种不同的网络通信模型,现现在NIO已经大量应用在Jetty.ZooKeeper.Netty等开源框架中 ...
- Web Service——CXF
1. 什么是CXF Apache CXF = Celtix + Xfire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.Apache CXF ...
- 工具-VIM配置
设置缩进的空格数 shiftwidth=4 设置制表符宽度 tabstop=4 高亮显示当前行 cursorline 高亮显示当前列 cursorcolumn
- Servlet线程安全性
问题:使用以下的代码演示servlet的线程安全问题? public class MultiThreadQuestion extends HttpServlet { public int count ...
- IOS开发之瀑布流照片墙实现
想必大家已经对互联网传统的照片布局方式司空见惯了,这种行列分明的布局虽然对用户来说简洁明了,但是长久的使用难免会产生审美疲劳.现在网上流行一种叫做“瀑布流”的照片布局样式,这种行与列参差不齐的状态着实 ...