Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm running the following PowerShell script on my SharePoint server to create a new host-header site collection and a tenant admin site:

Add-PSSnapin microsoft.sharepoint.powershell -ea SilentlyContinue

$featurePackID = "23b570e2-61f8-40ca-8e4d-7625ac7a4d37"
$webApplicationURL = "https://myserver"
$url = "https://test.mysharepoint.com" 
$owneralias = "TEST\SP_App01"
$contentDatabase = "WSS_Content_WebApp01"
$template = "STS#0"

$sub = New-SPSiteSubscription

if(!$url.StartsWith("https://")){ $url = "https://$url"; }
if(!$url.StartsWith($webApplicationURL))
{ 
    $hostheader = 'y' 
} 

#Set Feature Pack
if ($featurePackID -ne "")
{
    $FeaturePack = Get-SPSiteSubscriptionFeaturePack $featurePackID
}
if($FeaturePack -ne "" -and $FeaturePack -ne $null){
  Set-SPSiteSubscriptionConfig $sub -FeaturePack $FeaturePack
}

if($hostheader -ieq 'y' -or $hostheader -ieq 'yes'){
  #Pre-Reqs
  if( (Get-SPManagedPath -HostHeader "admin" -ea SilentlyContinue) -eq $null){$void = New-SPManagedPath "admin" -hostheader -explicit}

  $wa = Get-SPWebApplication $webApplicationURL
  New-SPSite $url -owneralias $owneralias -sitesubscription $sub -hostheaderwebapplication $wa -template $template -contentdatabase $contentdatabase #| set-spsite -maxsize 5000000 -warningsize 4000000 
  New-SPSite "$url/admin" -owneralias $owneralias -sitesubscription $sub -template "TENANTADMIN#0" -Administrationsitetype "TenantAdministration" -hostheaderwebapplication $wa -contentdatabase $contentdatabase #| set-spsite -maxsize 5000000 -warningsize 4000000 

}
else{
  New-SPSite $url -owneralias $owneralias -sitesubscription $sub -template "STS#0" | set-spsite -maxsize 5000000 -warningsize 4000000
  New-SPSite "$url/admin" -owneralias $owneralias -sitesubscription $sub -template "TENANTADMIN#0" -Administrationsitetype "TenantAdministration" | set-spsite -maxsize 5000000 -warningsize 400000
}

However I'm getting the following error:

New-SPSite : Object reference not set to an instance of an object. + New-SPSite <<<< $url -owneralias $owneralias -sitesubscription $sub -hostheaderwebapplication $wa -template $template -contentdata base $contentdatabase #| set-spsite -maxsize 5000000 -warningsize 4000000 + CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletNewSite:SPCmdletNewSite) [New-SPSite], NullReferenceException + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewSite

Any ideas why?

share|improve this question
    
Sorry, I missed the '!' at the beginning of statement 12. The featurePackId, is that a custom feature. –  Rich Ross Sep 15 '11 at 12:17
    
Yes, however I just tried running the script without setting up the feature pack and still the same problem –  Sam Huggill Sep 15 '11 at 12:27
    
It seems to be a problem with the template name - when I drop that parameter, the site gets created –  Sam Huggill Sep 15 '11 at 12:49
    
So, I set FPId to "" and changed the variables to match my environment. It creates the site using the code in line 35. It fails on the next line as I do not have 'admin' in my managed path list. Could this be permissions issue? –  Rich Ross Sep 15 '11 at 12:54
    
If you say it fails on the template, could you verify that the template is available and works (eg from GUI) –  Anders Rask Sep 15 '11 at 13:12

1 Answer 1

up vote 0 down vote accepted

This turned out to be a permissions error. I re-ran the script, without specifying the template, but set my account as the OwnerAlias. Then I ran this script to set the template:

Get-SPSite https://test.mysharepoint.com | Set-SPSite -Template "TenantAdmin#0" -Administrationsitetype "TenantAdministration"

And hey presto - all working. Then I went in and changed the Owner happily.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.