Thursday, November 26, 2009

PowerShell | Create New SPWebApplication + New SPSite

My thanks go to Arpah Shah's great video

mms | URL

#this code creates a new web application in specified port

Write-Host "Please specify the Farm Administrator credentials"
$FarmCredential = Get-Credential "Administrator"
$NewPort = Read-Host -Prompt "Please Insert New Port for Web Application"

$spfarm = get-spfarm

if($spfarm -ne $null)
$SPManagedAccount = Get-SPManagedAccount $FarmCredential.UserName
Write-Host "Creating New Web Application"
$webApp = New-SPWebApplication -Name "SharePoint - $NewPort" -ApplicationPool "SharePoint - $NewPort" -ApplicationPoolAccount $SPManagedAccount
$new_website=New-SPSite -url "http://localhost:$NewPort" -OwnerAlias $FarmCredential.Username -Language 1033 -Template "STS#0"

Make a new web application, one line code:
PS C:\Users\jdoe> New-SPWebApplication -Name Contoso Internet Site -Port 80 -HostHeader -URL -ApplicationPool ContosoAppPool -ApplicationPoolAccount (Get-SPManagedAccount DOMAIN\jdoe)

New-SPWebApplication -Name "tiago site" -Port 81 -Url http://sharepoint2010 -ApplicationPool tiagopool81 -ApplicationPoolAccount "NETWORKSERVICE"
New-SPSite -Url http://sharepoint2010:81/ -Name "tiago 81" -Template STS#0 -OwnerAlias tiagoduarte

No comments:

Post a Comment