标签:
# $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
标签:
原文地址:http://www.cnblogs.com/ansuyu/p/4553074.html