文字描述比较不容易说清楚,直接贴代码吧
# 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 $WebAppNameif($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 InfoWrite-HostWrite-Host "------------------------------" -foregroundcolor GreenWrite-Host "Name:" $WebApp.Name -foregroundcolor YellowWrite-Host "URL:" $WebApp.Url -foregroundcolor YellowWrite-Host "------------------------------" -foregroundcolor Green
在每次处理的时,都要添加 Microsoft.SharePoint.PowerShell,否则会出错的。