通过PowerShell创建SharePoint Web

代码如下(保存到本地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=0;$i -le $webApps.count-1;$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 0)
    {
        #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=0;$i -le $siteCollections.count-1;$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

时间: 2024-12-12 15:48:50

通过PowerShell创建SharePoint Web的相关文章

使用PowerShell 创建SharePoint 网站

使用PowerShell 创建SharePoint 网站 在SharePoint开发中,你应该学会使用PowerShell管理SharePoint站点.SharePoint Management Shell是一个Windows PowerShell模块,你可以用它高效管理SharePoint 用户.站点.网站集和组织. 这里教你简单的语句,创建一个SharePoint网站. 输入一下语句.红色框内信息是按下Enter后出现的. 建立的网站如下: 首先我们需要理解如何使用PowerShell创建站

通过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 1) { Write-Host "You have only one web applicatio

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint Lists

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.sharepoint.powershell function CreateSPLists() { $sites = Get-SPSite if($sites.count -eq 0) { Write-Warning "There is no site available." CreateSPLists } else { Write-Host "C

SharePoint网站测试数据自动化系列——通过PowerShell创建SharePoint List Items

代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin microsoft.sharepoint.powershell function CreateSPListItems() { $sites = Get-SPSite if($sites.count -eq 0) { Write-Warning "There is no site available." CreateSPListItems } else { Write-Host

PowerShell创建SharePoint 权限等级

参考:https://social.technet.microsoft.com/wiki/contents/articles/18661.sharepoint-2010-update-a-permission-level-using-powershell.aspx $sites = get-spsite -Limit ALL –webapplication http://mywebapplication.com ForEach ($site in $Sites) { # The URL to t

Powershell配置SharePoint环境

Powershell配置SharePoint环境 1. 设置outgoing email: 1) Powershell: $loadasm =[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $SPGlobalAdmin = New-Object Microsoft.SharePoint.Administration.SPGlobalAdmin $SPGlobalAdmin.UpdateM

powershell 操作sharepoint命令集

打开SharePoint 2013 Management Shell, and then run as administrator.执行如下命令 1. 添加wsp和安装Add-SPSolution -LiteralPath "C:\DeployResource\WSP\test.wsp"Install-SPSolution -Identity "test.wsp" -WebApplication "http://domain:port/" -GA

Powershell配置SharePoint环境(续)

Powershell配置SharePoint环境 1. 配置incoming email: $loadasm =[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $Farm =[Microsoft.SharePoint.Administration.SPFarm]::Local $IncomingMailService = [Microsoft.SharePoint.Administrat

使用Visual Studio 创建可视Web Part部件

使用Visual Studio 创建可视Web Part部件 可视Web Part部件是非常强大的Web 部件,它提供内置设计器创建你的用户界面.本文主要讲解如何使用Visual Studio 创建可视Web Part部件. 准备,创建一个自定义列表Stats,添加某些栏目,填充部分数据. 其中,栏目的数据类型为: 1. 打开Visual Studio,新建空白SharePoint项目SmallvilleVisualWPProject.选择部署为场解决方案. 2. 右击项目添加新项--可视Web