workflow PowerShell script

May 29, 2012 at 1:54 AM
Edited May 30, 2012 at 2:32 AM

*** updated 29 May ***

I have a client who I am building a site, and I just need to be able to run two powershell scripts for creating new sites (jobs for them) that enables the publishing feature and builds a specific folder structure.

I have gotten the script working so that it can be ran from powershell or SharePoint Mngt shell, however I cannot get the damn thing to run!

Everytime I run the workflow (it prompts for a couple things) I only get a permission denied for the domain administrator (the account I am logged in under).  I have add-spshelladmin for every service account, along with admin of corse, have ensured that the script is readable by all, turned off UAC but still cant get the damn thing to run!

The error reported by the workflow is

Error while executing PowerShell Script: You need to have Farm administrator priviliges to run this cmdlet.

I have checked the Event Viewer and the ULS logs for clues and cant find anything that I would think related.


***** addendum ****

I have also successfully ran my library/folder creation script with my app pool account. along with added network service and local serice via add-spshelladmin. All the above accounts are also members of wss_admin_wpg. 

If not via powershell, does anyone have any ideas on something that can create a picture library and folder structure either through a workflow or somthing that can be kicked off via workflow (or ilovesharepoint advanced workflow actions!) ?

Crying aside, beautiful solution! the site creation action works beautifully for me!

May 30, 2012 at 6:39 AM
Edited May 30, 2012 at 6:43 AM

The action will run under the credentials of the App Pool / SPTimer service. I would recommend to use the object model directly without the cmdlets.

e.g. create a site collection

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

$siteCol = $webApp.Sites.Add("http://intranet/sites/test", "test site col", "test desc",  1033, "STS#0", "contoso\admin", "admin", "")

 e.g. create web

$site = new-object Microsoft.SharePoint.SPSite('http://intranet/sites/test')

$web = $site.RootWeb.Webs.Add("subweb1", "sub web title", "description", 1033, "STS#0", $true, $false)


Jan 6, 2015 at 11:35 AM
Could you please tell me how to create content db ?

I am using below code but getting error:
Error while executing PowerShell Script: You need to have Farm administrator priviliges to run this cmdlet.

my code:
$webapp2 = Get-SPWebApplication -Identity $webapp
for($i=0;$i -lt $webapp.Sites.Count;$i++){
if($webapp.Sites[$i].Url -eq $siteName){
    #Remove-SPSite $siteName
Write-Host "exists already"

Create contendb

$dbs = Get-SPContentDatabase
for($i=0;$i -lt $dbs.Count;$i++){
if($dbs[$i].Name -eq $databaseName){
   # Remove-SPContentDatabase -Identity $dbs[$i].ID -Force

$res = New-SPContentDatabase -Name $databaseName -DatabaseServer $databaseServer -WebApplication $webapp2

And this code is working using power shell window but not working while I m call path on designer workflow.