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 ...
随机推荐
- 检查用户输入信息是否完整(vb.net实现)
机房收费系统中.在将用户输入的信息封装到实体中作为參数传到B层之前,总要对用户输入的信息进行检查.我将这种检查分为两类: 合法性检查 完整性检查 所谓合法性检查,就是用户输入的信息是否 ...
- FPGA视频拼接器的DP 的4k 功能输入, 把lvds 转为 serdes
4k(3840 x 2160 @60hz)越来越成为一种视频趋势,怎样把4K 接入到拼接器中.是一个棘手的问题. 先看一下原理图的接口: 这是 anx1122的 lvds的接口. 以下看一下系统的框架 ...
- Tomcat 监控方法
Tomcat 监控方法 方法1:.使用tomcat自带的status页 具体方法: 步骤1:修改%tomcat安装路径%\conf \tomcat-users文件,配置admin设置权限.在<t ...
- Loadrunner脚本编程(2)-VuGen脚本文件的开发过程
http://www.360doc.com/content/10/0806/13/1698198_44076570.shtml 1.定义测试项目的目标,环境,脚本,测试数据,硬件等.脚本应该符合编码规 ...
- Oracle单实例启动多个实例
Oracle多实例运行,单个实例就是一个数据库!,一个数据库对应多个实例是RAC Linux建立oracle的实例步骤: 1.在linux服务器的图形界面下,打开一个终端,输入如下的命令: xhost ...
- Java 性能测试的四项原则
绝大数的开发人员在日常工作过程中都会或多或少的遇见过性能问题,本文旨在阐述性能测试的理论,从而为性能分析和开发人员做指导.本文对于那些刚刚接触性能调优和正在解决问题的开发人员也能提供一些启发性的思路. ...
- message 弹出窗口
import javax.swing.JOptionPane;public class gong { public static void main(String [] args){ ...
- 如何查看USB方式连接Android设备的外接设备信息
1,USB存储设备(如:U盘,移动硬盘): //USB存储设备 插拔监听与 SD卡插拔监听一致. private USBBroadCastReceiver mBroadcastReceiver; In ...
- MySQL 如何更新某个字段的值为原来的值加1
格式:update 表名称 set 字段名称 = 字段名称 + 1 [ where语句] 比如说数据库中有一张student表,要想把id为1的学生成绩(score)加1则update student ...
- struts2 页面标签或ognl表达式取值--未完待续
一.加#号取值和不加#号取值的解说 1.s:property 标签——value属性使用事项 1)涉及问题:取值时什么时候该加#,什么时候不加? 2)介绍 <s:property value=& ...