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 ...
随机推荐
- 激活web容器对静态资源的默认servlet处理
在某些servlet的url匹配模式使用/时会拦截一些静态的资源的请求导致无法正确访问,可以采取web容器默认的servlet来处理,当然那些mvc一般也都提供了处理的方法,用何种方式可以自行决定,这 ...
- python之函数用法iter()
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法iter() #iter() #说明:对一个对象调用 iter() 就可以得到它的迭代 ...
- newInstance() 的参数版本与无参数版本
通过反射创建新的类示例,有两种方式: Class.newInstance() Constructor.newInstance() 以下对两种调用方式给以比较说明: Class.newInstance ...
- 【laravel5.4】自定义公共函数的创建
原文地址:http://blog.csdn.net/qq_38125058/article/details/76862151 公共函数,简单来说就是在任何地方都可以直接使用这个函数.简单介绍两种实现方 ...
- 使用Apache FtpServer
Java大法一统天下.遇到任何问题,先查一下Java中的解决方案. 地球上的许多事情,在Java中都能找到完美的解决方案. FtpServer是apache MINA项目的一个子项目,它实现了一个ft ...
- 使用ajax和window.history.pushState无刷新改变页面内容和地址栏URL (转)
在访问现在很火的google plus时,细心的用户也许会发现页面之间的点击是通过ajax异步请求的,同时页面的URL发生了了改变.并且能够很好的支持浏览器的前进和后退.不禁让人想问,是什么有这么强大 ...
- Android开发学习之SQLite数据存取浅析
一.SQLite的介绍 1.SQLite简介 SQLite是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入 式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低 ...
- Linux命令-终止进程命令:killall
强制杀死所有进程,注意它后面跟着是进程名而不是进程号 killall - httpd 杀死apache所有进程pstree -p | grep httpd 查看apache进程就没有了service ...
- 史上最简单的ButterKnife配置教程
网上的教程感觉都是抄来抄去,没一个靠谱的 还是自己丰衣足食搞一个ButterKnife配置教程吧.. 我的Android Studio版本是3.3. 1.dependencies中添加依赖 imple ...
- Linux内核同步 - RCU基础
一.前言 关于RCU的文档包括两份,一份讲基本的原理(也就是本文了),一份讲linux kernel中的实现.第二章描述了为何有RCU这种同步机制,特别是在cpu core数目不断递增的今天,一个性能 ...