码迷,mamicode.com
首页 > Web开发 > 详细

PowerShell基于已有网站模板文件创建网站集

时间:2015-06-04 22:32:03      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

 

#
$Loc = [System.Int32]::Parse(1033)     #英文版
$AdminUser = "Domain\User"             #管理员账户
$SiteUrl = "http://ServerName/"        #新建网站集URL
$SiteTitle = "New Site"                #新建网站标题
$SiteTemplatePath = "C:\NewSite.wsp"   #网站模板文件路径
$SiteTemplateName = "NewSite"          #网站模板名

# 加载 Microsoft.SharePoint.PowerShell
$Snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell‘}
if($Snapin -eq $null){
    Write-Host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

# 网站是否已经存在
$CheckObj = Get-SPSite -Identity $SiteUrl -ErrorAction SilentlyContinue
if($CheckObj -ne $null){
    Write-Host "The site [" $SiteUrl "] is existed.Deleting......" -Foregroundcolor Yellow
    Remove-SPSite -Identity $SiteUrl -Confirm:$false 
    Write-Host "The site [" $SiteUrl "] is deleted successful." -Foregroundcolor Green
}
# 创建新的网站集
Write-Host "Creating new site [" $SiteUrl "]. Please waiting......"  -Foregroundcolor Yellow
$Site = New-SPSite -Url $SiteUrl -OwnerAlias $AdminUser -Name $Title
Write-Host "The site [" $SiteUrl "] is created successful" -Foregroundcolor Green

# 上传网站模板文件
Write-Host "Upload site template to [" $SiteUrl "]. Please waiting......"  -Foregroundcolor Yellow
Add-SPUserSolution -LiteralPath $SiteTemplatePath -Site $SiteUrl
Do
{
    Write-Host "Waiting ...."
    Start-Sleep -Seconds 5;
    Try
    {
        $TemplateSolution = Get-SPUserSolution -Identity $SiteTemplateName -Site $SiteUrl -ErrorAction SilentlyContinue
    }
    Catch{}
}While(!$TemplateSolution)
Install-SPUserSolution -Identity $SiteTemplateName -Site $SiteUrl
Write-Host "Upload site template is successful"  -Foregroundcolor Yellow

# 应用网站模板到根网站
Write-Host "Apply site template to [" $SiteUrl "]. Please waiting......" -Foregroundcolor Yellow
$Web = GET-SPWeb $SiteUrl
$SiteTemplate = $Site.GetWebTemplates($Loc) | ?{ $_.Title -eq $SiteTemplateName}
$SiteTemplateId = $SiteTemplate.Name.Split("#")[0]
$Web.ApplyWebTemplate($SiteTemplateId)
Write-Host "Apply site template successful" -ForegroundColor Green


 

PowerShell基于已有网站模板文件创建网站集

标签:

原文地址:http://www.cnblogs.com/ansuyu/p/4553074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!