转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

代码如下(保存到本地ps1文件中,右键run with PowerShell即可):

Add-PSSnapin Microsoft.SharePoint.PowerShell
function createSPWeb()
{
$webApps = Get-SPWebApplication
chooseWebAppAndSelectSite $webApps
}
function chooseWebAppAndSelectSite($webApps)
{
Write-Host "Web applications in the farm:" -ForegroundColor Yellow
for($i=;$i -le $webApps.count-;$i++)
{
$tip = "[" + $i.ToString() +"]" + $webApps[$i].name
Write-Host $tip -ForegroundColor Green
}
$choice = Read-Host "Select the web application, enter the number before"
$siteCollections = Get-SPSite -WebApplication $webApps[$choice].url
if($siteCollections.count -eq )
{
#Write warning tip here.
Write-Warning "There is no site collection under the web application, you need to make an alternative choice."
chooseWebAppAndSelectSite $webApps
}
else
{
Write-Host "Site collections under the web application:" -ForegroundColor Yellow
for($i=;$i -le $siteCollections.count-;$i++)
{
$tip = "[" + $i.ToString() + "]" +$siteCollections[$i].url
Write-Host $tip
}
$choice = Read-Host "Select the site collection, enter the number before"
$tip = "You want to create a new web(subsite) under the site collection " + $siteCollections[$i] + "? Enter 'y' to verify"
Write-Host $tip -ForegroundColor Cyan
$newChoice =Read-Host
if($newChoice -eq "y")
{
$name = Read-Host "Please enter the name of the web(subsite)"
$webUrl = $siteCollections[$choice].url + "/" + $name
write-host "The web(subsite) is creating, please wait for a moment..." -ForegroundColor DarkGreen
New-SPWeb -Url $webUrl -Name $name -Template "STS#0"
Write-Host "The web(subsite) has been created. The url is above." -ForegroundColor Green
}
}
}
createSPWeb

运行界面:

创建Site Collection的脚本,详见上一篇blog

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

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

    通过PowerShell创建SharePoint Site Collection,代码如下: Add-PSSnapin microsoft.sharepoint.powershell function ...

  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自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  9. SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

    Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...

随机推荐

  1. RESTFul中的那些事(2)----怎样支持RESTFul的HTTP Patch方法?

    我们在调用RESTFul服务的时候,有的时候.第三方的服务会提供支持PATCH 操作的方法,在这样的情况下.我们假设我们以下的这样的方式, 去调用PATCH操作.肯定会返回40X的错误. PATCH ...

  2. 使用java爬取国家统计局的12位行政区划代码

    前言: 本文基于j2ee的原始url进行都写,解析指定内容时也是使用很傻的形式去查找指定格式的字符串来实现的. 更优雅的方式是可以使用apache的HttpClient和某些文档模型将HTML字符串构 ...

  3. Javascript获取当月的天数

    var d = new Date(); var curMonthDays = new Date(d.getFullYear(), (d.getMonth() + 1), 0).getDate(); a ...

  4. linux修改 时间 时区

    linux系统修改系统时间与时区 | 浏览:3486 | 更新:2014-06-18 19:36 1 2 3 4 5 6 7 分步阅读 有装过Linux系统的人,可能都会有这样的经历,就是该机器安装w ...

  5. docker登录没有配置https的harbor镜像仓库

    已经搭建harbor 仓库 ,域名  172.16.1.99 出现问题: 客户端尝试登录 仓库 [root@localhost docker]# docker login 172.16.1.99:80 ...

  6. get请求乱码情况

    编写一个RegistServlet处理用户的Get请求数据 public void doGet(HttpServletRequest request, HttpServletResponse resp ...

  7. mybatis&Hibernate区别

    mybatis是一个不完全的orm框架,因为mybatis需要程序员自己写大量的sql,需要程序员对sql的掌握比较高,不过mybatis可以通过xml文件可以灵活的配置要运行的sql语句,将sql与 ...

  8. Mybatis中的@SelectKey注解

    一.创建Maven项目 在pom.xml中,添加mybatis依赖,mysql-jdbc依赖,把编译版本改为1.8 你问,为啥mybatis不会自动依赖mysql-jdbc,需要手动写明?答:因为my ...

  9. java JAXB + STAX(是一种针对XML的流式拉分析API)读取xml

    JDK1.5需要添加jar包,1.6以后就不需要了<dependency> <groupId>stax</groupId> <artifactId>st ...

  10. centos7 搭建go环境

    下载go #cd /home #mkdir app #cd app #wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar. ...