Thursday, December 20, 2012

PowerShell Script to Create Site Collections for SharePoint 2013

After setting up my SharePoint 2013 farm with Host Name Site Collections I wanted a quick easy way to create a new Site Collection, since you can't do it properly through Central Admin.

So I sat down and wrote this PowerShell script that will prompt the user for all necessary information to create a new SC with an option of creating a new Database.

To run you can copy the below script and paste it into a ps1 file.


Add-PSSnapin Microsoft.SharePoint.Powershell
Write-Host "This script can be used to create Site Collections for SharePoint 2013"
$webApp = Get-SPWebApplication | Where-Object {$_.DisplayName -eq "SharePoint HNSC Host - 80"}
IF ($webApp){
 $ans = Read-Host "I found a HNSC Host Web App, would you like me to use it?. Y or N"
 
}
ELSE {
 $ans = 'N'
}
IF ($ans -eq 'N' -or $ans -eq 'n') {
 $webApp = $null
    Write-Host "Here are the web applications I see on your farm"
    Get-SPWebApplication
 while (!$webApp) {
  $webAppName = Read-Host "What is the DisplayName of the Web Application you'd like to use? "
  $webApp = Get-SPWebApplication | Where-Object {$_.DisplayName -eq $webAppName}
  IF (!$webApp) {Write-Host "I didn't find a Web Application with that name. Be sure to enter the full name exactly as it's listed above."}
 }
}
$siteName = Read-Host "Site Name"
$siteDescription = Read-Host "Site Description"
$siteUrl = Read-Host "Site Url (ie http://site.sp2013.com)"
$seeTemplates = Read-Host "Would you like to see a list of templates codes? Y or N"
IF ($seeTemplates -eq 'y' -or $seeTemplates -eq 'Y') {Get-SPWebTemplate}
$siteTemplate = Read-Host "Site Template (ie Blank - STS#0, Team STS#1, etc)"
$siteAdmin = Read-Host "Site Admin (ie ms\devspadmin)"
$createDB = Read-Host "Finally would you like to create a new Content Database for this Site Collection?"
$db = $null
IF($createDB -eq 'Y' -or $createDB -eq 'y') {
    $dbName = Read-Host "Database Name"
    Write-Host "Creating Database..."
    $db = New-SPContentDatabase -name $dbName -webApplication $webApp
}
ELSE {
    Get-SPContentDatabase -webapplication $webApp
    while(!$db) {
        $dbName = Read-Host "What Content Database would you like to use?"
        $db = Get-SPContentDatabase -Identity $dbName
        IF (!$db) {Write-Host "I didn't find a Content Database with that name. Be sure to enter the full name exactly as it's listed above." }
    }
}
Write-Host "Creating Site Collection..."
New-SPSite -Name $siteName -Url $siteUrl –HostHeaderWebApplication $webApp -Template $siteTemplate -OwnerAlias $siteAdmin -ContentDatabase $db -Description $siteDescription
Write-Host "Script Complete"

 
- Owen Runnals
SharePoint Practice Manager @ General Networks Corp

Tuesday, December 18, 2012

SharePoint 2013 Workflow Not Available w/ Blank Site Template

When setting up Workflow Manager 1.0 with your SharePoint 2013 farm it's important to note that a site that is created with the Blank Template (STS#0 if created w/ PowerShell) doesn't have a critical feature enabled that allows you to create SharePoint 2013 workflows in that site.

Update: It seems other templates are also missing this, like the Document Center template.

The feature is called "WorkflowServiceStore" and is enabled by default on the Team Site (and most likely all the other). The only way (that I've found) that you can activate this feature is through PowerShell as there are no related Features in the Site Features section on the site.

You can use the following PowerShell:

Enable-SPFeature -Identity WorkflowServiceStore -Url http://yoursiteurl

Otherwise you'll see this screen when you try to create a workflow, even though your server may be configured properly.


Message text: "The option for the SharePoint 2013 Workflow platform is not available because the workflow service is not configured on the server. Please contact your server administrator"

- Owen Runnals
SharePoint Practice Manager @ General Networks Corp