SharePoint: Create Site Collection Using PowerShell

cls
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.Powershell

$siteName = "SiteName"
$port = 80
$hostHeader = "public.SiteName.com"
$url = "http://public.SiteName.com"
$appPoolName = "SiteName Public"

$managedAccount = "managed Account"

$dbServer = "DB Server Name"
$dbName = "DB Name"
$allowAnonymous = $true
$authenticationMethod = "NTLM"
$ssl = $false

$template = Get-SPWebTemplate "STS#0"
# Please dont change line below as script need to run under the account of logged in user
$siteAdmin = $env:userdomain + "\" + $env:username;

#Remove-SPWebApplication -identity $url -Confirm

New-SPWebApplication -Name $siteName -Port $port -HostHeader $hostHeader -URL $url -ApplicationPool $appPoolName -ApplicationPoolAccount (Get-SPManagedAccount “$managedAccount”) -DatabaseName $dbName -DatabaseServer $dbServer -AllowAnonymousAccess:$allowAnonymous -AuthenticationMethod $authenticationMethod -SecureSocketsLayer:$ssl


New-SPSite -Url $url -OwnerAlias $siteAdmin -Template $template

Write-Host "If you are running it locally make to sure to update host file entries" -ForegroundColor Yellow
Write-Host "127.0.0.1       public.SiteName.com" -ForegroundColor Yellow



Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell