Jul 2, 2008

SharePoint Designer PowerShell Activity

The first Code I've published on i Love SharePoint is the SharePoint Designer PowerShell Activity. Anything PowerShell can do, anything the Activity can do - that's really a lot!

Quick Start (Installation see ReadMe.txt):

  • The example creates a new Site based on the Workflow's List Item Title.
  • Add the Activity to a SharePoint Designer Workflow



  • Insert the following PowerShell Script:


    $web.Webs.Add($item.ID.ToString(),$item.Title,"Created by PowerShell",1031,"STS#0",$false,$false);

    $web.Dispose();

  • Save
  • Run the Workflow. The Workflow now creates a Site named like the List Item. The URL of the Site will be the ID of the Item.

That's just one trivial example. Any ideas how to use, please tell me...

Quick Reference:

In your PowerShell Script you can use the following Variables:

  • $site = current SPSite
  • $web = current SPWeb
  • $list = the List of the Workflow SPList
  • $item = the SPListItem of the Workflow
  • $variable1 = the Workflow Variable you defined for Variable1 in the SharePoint Designer (=$null if you have not defined)
  • $variable2 = the Workflow Variable you defined for Variable1 in the SharePoint Designer (=$null if you have not defined)

You can set the two Workflow Variables within the Script through returning a Hashtable
(keep care on correct types)= @{"variable1"="my Value1";"variable2"=4711};

Errors could be found in the Event Log.

WARNING: This Activity might cause huge security vulnerabilities!

Any comments would be appreciated.

26 comments:

Chanda said...

Christian,

Thanks for the great custom SPD activity! I'm new to PowerShell so maybe that's where I'm running into an issue and I'm wondering if you could help. I'm using v1.2.

I have installed the solution and it's accessible in SPD, however I think I just can't get the syntax correct. I am trying to perform a substring function in order to get the portion of a string after a specific character (#).

The script I'm using in the SPD activity is:

@{"variable1"=[%Variable: MyVar%];
$Index = $variable1.IndexOf('#');
$variable1.Substring($Index);

When I run the workflow it errors and the workflow history reports "Error Executing PowerShell Script. Missing '=' operator after key in hash literal."

If I try to assign static text to variable1:

@{"variable1"="8;#John Smith";
$Index = $variable1.IndexOf('#');
$variable1.Substring($Index);

the workflow also errors and the workflow history reports "Error Executing PowerShell Script. You cannot call a method on a null-valued expression."

Is there something I've gotten wrong with the syntax?

Thanks!
Chanda

Chanda said...

Christian,

I've made some progress, now the workflow completes successfully using the following script and I get "John Smith" as a result:

$a = "8;#John Smith";
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

The issue I am running into now is that if I attempt to use a workflow variable instead of static text the workflow errors and the workflow history reports "Error Executing PowerShell Script. Method invocation failed because [System.Int32] doesn't contain a method named 'IndexOf'."

Here is the script I'm using now:

$a = [%Variable: Name%];
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

Any instructions on how to use workflow variables within the PowerActivity string builder?

Thanks again,
Chanda

Chanda said...

Christian,

I've made some progress, now the workflow completes successfully using the following script and I get "John Smith" as a result:

$a = "8;#John Smith";
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

The issue I am running into now is that if I attempt to use a workflow variable instead of static text the workflow errors and the workflow history reports "Error Executing PowerShell Script. Method invocation failed because [System.Int32] doesn't contain a method named 'IndexOf'."

Here is the script I'm using now:

$a = [%Variable: Name%];
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

Any instructions on how to use workflow variables within the PowerActivity string builder?

Thanks again,
Chanda

Chanda said...

Christian,

I've made some progress, now the workflow completes successfully using the following script and I get "John Smith" as a result:

$a = "8;#John Smith";
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

The issue I am running into now is that if I attempt to use a workflow variable instead of static text the workflow errors and the workflow history reports "Error Executing PowerShell Script. Method invocation failed because [System.Int32] doesn't contain a method named 'IndexOf'."

Here is the script I'm using now:

$a = [%Variable: Name%];
$index = #a.IndexOf("#");
$output = $a.Substring($index + 1);

Any instructions on how to use workflow variables within the PowerActivity string builder?

Thanks again,
Chanda

Chanda said...
This comment has been removed by the author.
Christian said...

Chanda,

simply surround the [%Variable: Name%] with quotes: "[%Variable: Name%]". So it will be interpreted as a string.
Bye, Christian

Sascha said...

Christian,
Great SPD Add-On.

Just my problem: we host a shared solution for my company where some developers would be so thankfull for this tool. But can I restrict the usage? Otherwise anyone with access to SDP and with the ownership on some site would be able to play havoc on the farm....

-Sascha

Christian said...

Thanks Sascha, unfortunatley you can't limit the usage at the site level. Only per web app (web.config). SharePoint designer doesn't allow custom designers :( We use Nintex with our PowerActivity http://www.dataone.de/en/solutions/sharepointportals/Seiten/NintexWorkflowPowerActivity.aspx. This Activity can only be used by Farm Admins and the scripts will be autatically digital signed. I hope the SharePoint Designer will allow such scenarios in the future too. At the moment it doesnt't look good.
Bye, Christian

Sascha said...

Hi,
thanks for the fast answer. Bad news...

Would it be a solution to make a spinoff of your SPD activity which would take the filename of a local ps1 script instead of the code? This would make it possible to deploy only certified (and/or signed) scripts directly to the SharePoint server... Unsigned code on the dev box, signed code on the prod system....

-Sascha

Xj Cheng said...

Replica Handbags: Amount & Superior Consciousness!Our handmade Replica accoutrements are absolute artist delights consummate accessories for gucci replica the appearance conscious,at a atom of the amount of an aboriginal artist handbag.You could buy a Versace replica backpack for anniversary day of the anniversary for the amount of one aboriginal Versace handbag.Afar from you and Beubag.com,no one abroad will apperceive that your Versace replica backpack is louis vuitton replica a replica and not the actual original!From the aboriginal canicule to the present day the backpack is still a actualization icon,and over time the styles accept afflicted but accustomed a backpack still agency fashion.Most able who abrasion these Rolex replica watches accept accepted that they accept begin a new angel of themselves afterwards they accept started cutting these Rolex replica watches!So what are you cat-and-mouse for? Get one of the endless models of cartier replica the Rolex replica watches and see your activity change immediately.Not alone will the girls at the affair battery all their amore on you,you can be blow assured that even your bang-up will pay appropriate absorption at you.Rolex replica watches accomplish these wonders and lots more.Swiss replica watches are acclaimed all over their apple for their body and accomplish and you can acquisition a lot of celebrities cutting them and assuming off that they are anyone special.They wish to get the best out of activity for the least.Swiss replica watches provides them with an befalling to appearance off replica watches uk what is declared to be the best for the minimum cost.

Hug Day said...

hug day 2016 Images
happy hug day 2016 Date SMS Messages Quotes
Hug day Celebration Ideas For Him/Her
hug day sms for gf

风骚达哥 said...

20160423 junda
air jordans
cheap oakley sunglasses
kate spade outlet
adidas stan smith
ray ban sunglasses
michael kors outlet
nike air max shoes
cheap omega watches
yeezy boost 350
michael kors outlet online
michael kors outlet online
nike free runs
air jordan uk
michael kors outlet online
pandora charms
ray ban outlet
calvin klein outlet
fitflops sale clearance
toms outlet
nike huarache white
sac longchamp
toms outlet
michael kors outlet clearance
bottega veneta outlet
armani watches
gucci handbags
nike blazer
oakley sunglasses
true religion jeans
cheap jordans
ray bans
hollister
bottega veneta handbags
jimmy choo outlet
oakley sunglasses
converse
prada outlet
reebok shoes
true religion
burberry outlet

Libin Huang said...

20160426libinhollister clothing store
oakley sunglasses
michael kors handbags
tiffany outlet
ray-ban sunglasses
gucci outlet online
ray-ban sunglasses
burberry outlet online
coach outlet canada
ray-ban sunglasses
herve leger outlet
ray ban sunglasses sale
air max 90
oakley sunglasses
adidas wings shoes
michael kors outlet
michael kors factory outlet
louis vuitton bags
michael kors online outlet
nba jerseys
ralph lauren pas cher
oakley sunglasses
toms shoes
nike air max 90
nike tn pas cher
air max 90
lululemon outlet
nike air force 1
true religion outlet
michael kors outlet
burberry outlet store
ray ban sunglasses
kobe shoes
true religion outlet
discount michael kors handbags

Yuanyuan Lin said...

7.14llllllyuan"ferragamo shoes"
"chrome hearts outlet"
"air jordan shoes for sale"
"tory burch outlet online"
"hollister"
"michael kors outlet"
"ralph lauren femme"
"thomas sabo uk"
"adidas uk store"
"louis vuitton outlet"
"coach outlet"
"coach handbags"
"burberry outlet"
"coach outlet online"
"rolex watches"
"cheap oakley sunglasses"
"tiffany outlet"
"cheap football shirts"
"celine outlet online"
"michael kors handbags clearance"
"snapbacks wholesale"
"michael kors outlet"
"toms outlet store"
"true religion outlet uk"
"coach outlet store"
"oakley sunglasses"
"celine outlet"
"swarovski outlet"
"cheap snapbacks"
"longchamp pas cher"
"michael kors outlet online"
"fitflops clearance"
"nike roshe run"
"coach outlet online"
"oakley sunglasses"
7.14

Fangyaya said...

nike roshe one
cheap oakley sunglasses
cheap oakleys
michael kors bags
coach outlet store online
retro jordan shoes
louis vuitton purses
coach outlet online
coach factory outlet
burberry sale
red bottom shoes
michael kors handbags
retro 11
coach factory outlet
louis vuitton outlet
louis vuitton
ghd hair straighteners
louis vuitton handbags
coach outlet
ralph lauren outlet
coach factory outlet online
cheap ray ban sunglasses
true religion jeans
louis vuitton bags
ray ban sunglasses outlet
cheap ray ban sunglasses
longchamp outlet
coach outlet online
ralph lauren
gucci belts
ray ban outlet
ray ban outlet
michael kors handbags
fitflop shoes
coach outlet clearance
montblanc pens
toms shoes uk
ralph lauren clearance outlet
timberlands
retro jordans 13
20168.8chenjinyan

Robbert said...

It is the obligation of the undergrad to ascertain the advance sum required by him/her with exactness and afterward apply for the most appropriate utilized vehicle advance accessible. The understudy might however remember the extra costs like protection, repairs, and so on that may come up in the long run. check cashing

Justin said...

A private understudy advance is a choice that you can get in the event that you don't have any significant bearing for a government advance. There are numerous private moneylenders with fabulous projects for graduate credits. payday loans chicago

dada24 Xu said...

ysl outlet online
jordan shoes
vans outlet store
uggs sale
vans shoes
michael kors outlet
birkenstocks
ugg australia
borse gucci
celine outlet
2016921caiyan

chenlina said...

chenlina20160923
mont blanc pens
louis vuitton outlet
uggs australia
uggs on sale
adidas trainers
longchamp outlet
nike roshe run
ralph lauren
adidas shoes
coach outlet store online clearances

John said...

air force 1
birkenstock outlet
ugg sale
fitflops sale
michael kors outlet store
canada goose jackets
nike uk
converse all star
ralph lauren outlet online
coach outlet online
birkenstock outlet
abercrombie
polo ralph lauren outlet
adidas nmd r1
mcm outlet online
coach outlet online
timberland boots outlet
ed hardy store
true religion jeans outlet
nike cortez classic
timberland shoes
louis vuitton outlet online
birkenstock sale
louboutin outlet
michael kors handbags outlet
uggs sale
birkin handbags
rolex watches for sale
michael kors outlet store
vans outlet
polo ralph lauren outlet online
20161102yuanyuan

Meiqing Xu said...

armani exchange
cheap nike shoes
coach outlet
ugg boots canada
kd 9 shoes
christian louboutin sale
michael kors outlet
moncler outlet
uggs
yeezy 350 boost
20161221caiyan

chenmeinv0 said...

michael kors handbags
polo outlet
timberland outlet
le coq sportif shoes
oakley sunglasses
nike roshe
air jordan pas cher
michael kors handbags
ray ban sunglasses
michael kors
hzx20170228

chenmeinv0 said...

louis vuitton
true religion outlet
michael kors outlet online sale
ray ban sunglasses
ray ban sunglasses
louis vuitton
adidas nmd
adidas outlet
michael kors outlet
dallas mavericks jerseys
hzx20170228

Unknown said...

cartier outlet
fitflops sale clearance
sac louis vuitton pas cher
longchamp outlet online
mulberry uk
thomas sabo charms
cheap oakley sunglasses
cheap nike shoes
ray-ban sunglasses
ralph lauren
chanyuan2017.05.08

dong dong23 said...

coach outlet store online clearances
hermes outlet
supra outlet
mont blanc mountain pen
mlb jerseys cheap
true religion outlet
kobe 9 shoes
fred perry polo shirts
christian louboutin heels
michael kors outlet
2017.5.11chenlixiang

Home Improvement City of Yonkers said...

The team at Ajrin Construction Inc. is the best of the best general contractors and support staffs, as selected from within the industries over City of Yonkers NY based upon their achievements and their understanding of complex projects.Best Home Improvement Company City of Yonkers