SharePoint 2010 PowerShell 系列 之 Create WebApplication

学习目录

文字描述比较不容易说清楚,直接贴代码吧

# check to ensure Microsoft.SharePoint.PowerShell is loaded
$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"
}

Write-Host "Starting create WebApplication"
$WebAppName = "SharePoint - 999"
$WebAppPort = 999
$WebAppPool = "SharePoint - 999"
$WebAppDBName = "WSS_Content_999"

#Delete any existing Webapplication by name
$targetUrl = Get-SPWebApplication $WebAppName
if($targetUrl -ne $null){
    Write-host "Deleting existing webapplication:" $WebAppName
    Remove-SPWebApplication $WebAppName -confirm -DeleteIISSite -removeContentDatabase
    Write-host "Deleted Site and ContentDatabase successful." -foregroundcolor red
}


Write-Host "Please waiting......" -foregroundcolor green
$WebApp = New-SPWebApplication -Name $WebAppName -Port $WebAppPort -ApplicationPool $WebAppPool -DatabaseName $WebAppDBName -ApplicationPoolAccount (get-SPManagedAccount "T\Administrator")
Write-Host "WebApplication Created successfully"

#display WebApplication Info
Write-Host
Write-Host "------------------------------" -foregroundcolor Green
Write-Host "Name:" $WebApp.Name -foregroundcolor Yellow
Write-Host "URL:" $WebApp.Url   -foregroundcolor Yellow
Write-Host "------------------------------" -foregroundcolor Green

在每次处理的时,都要添加 Microsoft.SharePoint.PowerShell,否则会出错的。

 

posted @ 2012-06-30 21:58  @@@一统@@@  阅读(956)  评论(0编辑  收藏  举报