SharePoint自动化系列——通过PowerShell创建SharePoint Web

简介: 转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PSSnapin Microsoft.

转载请注明出自天外归云的博客园: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=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

相关文章
|
1月前
|
JavaScript 前端开发 测试技术
使用Selenium执行JavaScript脚本:探索Web自动化的新领域
本文介绍了如何在Selenium中使用JavaScript解决自动化测试中的复杂问题。Selenium的`execute_script`函数用于同步执行JS,例如滑动页面、操作时间控件等。在滑动操作示例中,通过JS将页面滚动到底部,点击下一页并获取页面信息。对于只读时间控件,利用JS去除readonly属性并设置新日期。使用JS扩展了Selenium的功能,提高了测试效率和精准度,适用于各种自动化测试场景。
46 1
|
3月前
|
存储 运维 应用服务中间件
[运维日志] Web 服务器日志依日期归档(Powershell 实现,附源代码)
[运维日志] Web 服务器日志依日期归档(Powershell 实现,附源代码)
74 0
|
3月前
|
前端开发 JavaScript Java
用Python实现高效数据记录!Web自动化技术助你告别重复劳动!
用Python实现高效数据记录!Web自动化技术助你告别重复劳动!
32 1
|
3月前
|
设计模式 Java 测试技术
软件测试/测试开发/全日制|Page Object模式:为什么它是Web自动化测试的必备工具
软件测试/测试开发/全日制|Page Object模式:为什么它是Web自动化测试的必备工具
54 0
|
5天前
|
XML Web App开发 测试技术
python的Web自动化测试
【4月更文挑战第16天】Python在Web自动化测试中广泛应用,借助Selenium(支持多浏览器交互)、BeautifulSoup(解析HTML/XML)、Requests(发送HTTP请求)和Unittest(测试框架)等工具。测试步骤包括环境搭建、编写测试用例、初始化浏览器、访问页面、操作元素、验证结果、关闭浏览器及运行报告。注意浏览器兼容性、动态内容处理和错误处理。这些组合能提升测试效率和质量。
11 6
|
2月前
|
Web App开发 测试技术 数据安全/隐私保护
Web自动化测试工具Selenium
Web自动化测试工具Selenium
|
2月前
|
JavaScript Java Python
Web自动化三种等待方式,一篇文章教会你
Web自动化三种等待方式,一篇文章教会你
65 1
|
3月前
|
数据采集 缓存 JavaScript
Python神器!WEB自动化测试集成工具 DrissionPage
Python神器!WEB自动化测试集成工具 DrissionPage
96 0
|
5月前
|
机器人 测试技术 持续交付
如何实现高效的Web自动化测试?
如何实现高效的Web自动化测试?
|
7月前
|
Web App开发 JavaScript 前端开发
web自动化测试工具之Selenium的使用
Selenium是一个功能强大的自动化测试框架,在自动化测试和Web应用开发中具有广泛的应用,能够提高测试效率、确保应用程序的质量,并帮助开发人员在不同环境中构建和调试Web应用程序。
244 1

热门文章

最新文章