Create Site Collection

Jul 21, 2011 at 12:43 PM

Is there a chance to create Site Collections by using the Create Site Action?

I would like to run a workflow automatically after Adding a new item to a list in (for example) http://sp2010.contoso.com/sites/site1 who creates a site collection (for example) http://sp2010.contoso.com/sites/site2

Thanks for your help!

Sep 23, 2011 at 3:28 AM

Did you ever get this working? I am able to kick off a site collection creation but the powershell workflow action seems not to be able to set a template upon creation.

Oct 5, 2011 at 3:10 PM

Hello. I am also curious if you were able to create a Site Collection using the "Create a Site" Action?

If not, is it possible to do this through "Execute PowerShell" action using the "New-SPSite" cmdlet?

Coordinator
Oct 9, 2011 at 5:21 PM

Hello,

this is possbile. I would not recommend using the SharePoint PowerShell snapin.  I would try it like this:

$webApp = [Microsoft.SharePoint.SPWebApplication]::Lookup("http://mywebapp")

$webApp.Sites.Add(...)

(http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spsitecollection.add.aspx)

Bye,

Chtistian

 

Oct 10, 2011 at 12:30 PM
Edited Oct 10, 2011 at 12:41 PM

Thanks a lot Christian. This works perfectly.

In previous attempts I used $site.WebApplication.Sites.Add(...). This doesn't work because you're opening the WebApplication from the context of the workflow user.

For people who are trying the same, use the method Christian described: use [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(...)

I was not able to use standard SP2010 cmdlets using the SharePoint PowerShell snapin. But you're able to use the whole object model, so the possibilities are limitless.

Jan 5, 2012 at 1:47 PM
Edited Jan 5, 2012 at 1:48 PM

Executing the SPWebApplication.Sites.Add() method gives me some Permission errors if I am using a standard Web Application Pool account. This account does not have any permissions to the Configuration DB. Running a Workflow from the Central Administration that creates a Site Collection through the method mentioned above is no problem, since the CA is running under the SPFarm account.

If you still would like to achieve to create Site Collections through a normal WebApplication, don't bother giving your Web Application Pool more permissions (that would be crap!!) but use the method underneath:

$webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(http://someurl) 
if ($webApp.SelfServiceSiteCreationEnabled) 
{ 
$siteCollection = $webApp.Sites 
$newSite = $siteCollection[0].SelfServiceCreateSite($ProjectSiteUrl, $ProjectName, "", 1033, "{F90E6CBE-49BE-4F78-A937-191DD04BLAA}#SomeSiteDefinition", $Owner, "Username", some@email.com, $Owner, "Username", some@email.com,) 
}

This method requires a lot less permissions, and you won't ****-up your least priviliges principles. Needless to mention you need to enable the SelfServiceSiteCreation on the Web Application your running the Workflow under.