1. Create a .ps1 file and add reference for PowerShell and SharePoint Assemblies.
2. Set variables and create Web Application.Add-PsSnapin Microsoft.SharePoint.PowerShell[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
3. Create Site Collection.#Create Web ApplicationWrite-Output " "
Write-Output "Creating Web Application for Intranet Portal."
$AppName = "Intranet Portall"
$AppPool = "IntranetPortalApplicationPool"
$UserAccount = "winsmarts\sp_admin"
$Port = 80$DBServer = "SPDEV\SQL_SERVER"
$DBName = "IntranetPortalDatabase_80"
New-SPWebApplication -Name $AppName -Port $Port -ApplicationPool $AppPool-ApplicationPoolAccount (Get-SPManagedAccount $UserAccount) -databaseserver $DBServer -databasename $DBNameWrite-Output " "
Write-Output "Web Application Created Successfully."
Write-Output " "
Write-Output "Creating Top Site Collection"
# Set variables$SiteCollectionName = "Test Portal"
$SiteCollectionURL = "http://SPDEV:80"
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033$SiteCollectionOwner = "winsmarts\Administrator"
# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage-Template $SiteCollectionTemplate -Name $SiteCollectionNameWrite-Output " "
Write-Output "Top Site Collection created successfully."
4. Create sub sites.
#Creating Sub Sites in top site collection.
Write-Output " "
Write-Output "Creating Sub Sites"
$SubSites = @("Central Services", "Knowledge Base", "Service Center", "IT", "HR", "Finance")for($i=0 ; $i -lt $SubSites.count ; $i++)
{clear-variable -name siteurl$SiteUrl = $SiteCollectionURL += "/"
$SiteUrl = $SiteUrl += $SubSites[$i]Write-Output " "
#Write-Output "Creating Site for " += $SubSites[$i]
Write-Output " "
New-SPWeb $SiteUrl -Template $SiteCollectionTemplate -Name $SubSites[$i] -UseParentTopNav-Language $SiteCollectionLanguageWrite-Output " "
#Write-Output "Site Created for " += $SubSites[$i]
Write-Output " "
}
No comments:
Post a Comment