Geeks With Blogs
Mark Jones

I am pleased to announce that it’s now possible (with release 1.2.3463.00) , to run STSADM commands from the SharePoint Action Framework (SAF). Hence, if you add the standard STSAdm commands (that ship with SharePoint) to the truly awesome collection that Gary Lapointe has developed, (available on his STSADM Blog), you are looking at over 250 useful SharePoint Actions.

This functionality has been made available by a new Action called “StsAdm”. The Action should be called via an Alias like this “Action.StsAdmin”. (Aliasing is for convenience so that you don’t have to put the full 4 part assembly reference into the Macro).

An example :

This example illustrates how to create a Macro that calls the new Action and executes 2 STSAdm commands to delete a group and also create the group.

<?xml version="1.0" encoding="utf-8" ?> 
<objects xmlns="http://www.springframework.net"> 
 
 <!-- Defines the main macro to process --> 
 <object id="MacroToProcess" type="Macro" > 
 <constructor-arg name="id" value="{8BB25F02-5E41-4e86-BCA2-E253747354A3}" /> 
 <constructor-arg name="actions"> 
 <list element-type="IAction"> 
 
 <!-- Runs the STSAdm Command--> 
 <object name="RunStsAdminCommands" type="Action.StsAdmin"> 
 <property name="EntityList" ref="StsAdminCommandList"/> 
 <property name="StopOnDoException" value="false"/> 
 </object> 
 
 </list> 
 </constructor-arg> 
 </object> 
 
 <!-- Holds a list of individual list Items to export --> 
 <object id="StsAdminCommandList" type="Entities"> 
 <constructor-arg> 
 <list> 
 <!-- Delete the Group using STSADM --> 
 <object type="Entity.StsAdminCommand"> 
 <property name="Operation" value="deletegroup" /> 
 <property name="Arguments"> 
 <dictionary key-type="string" value-type="string"> 
 <entry key="url" value="${CurrentWeb.Url}"/> 
 <entry key="name" value="SAF Demo Group"/> 
 </dictionary> 
 </property> 
 </object> 
 
 <!-- Create the Group using STSADM --> 
 <object type="Entity.StsAdminCommand"> 
 <property name="Operation" value="creategroup" /> 
 <property name="Arguments"> 
 <dictionary key-type="string" value-type="string"> 
 <entry key="url" value="${CurrentWeb.Url}"/> 
 <entry key="name" value="SAF Demo Group"/> 
 <entry key="description" value="This is a group create by SAF"/> 
 <entry key="ownerlogin" value="${CurrentUser}"/> 
 <entry key="type" value="owner"/> 
 </dictionary> 
 </property> 
 </object> 
 
 </list> 
 </constructor-arg> 
 </object> 
</objects> 
 
 

 

The StsAdmin Action

As can be seen from the example above, it’s pretty straight forward to use the StsAdmin command. You use the Action by adding this line :

<object name="RunStsAdminCommands" type="Action.StsAdmin">
  <
property name="EntityList" ref="StsAdminCommandList"
/>
  <
property name="StopOnDoException" value="false"
/>
</
object>

The StsAdminCommand Entity

As with every Action, all of the parameter information is passed into the Action via a simple Entity. The Entity in this case is called “Entity.StsAdminCommand”. This entity has 2 properties that need to be passed, the Operation and the Arguments. Please Note! It’s possible to supply as many entities as you like. These will all get executed as separate STSAdm commands.

<object type="Entity.StsAdminCommand"> 
   <property name="Operation" value="deletegroup" /> 
   <property name="Arguments"> 
     <dictionary key-type="string" value-type="string"> 
       <entry key="url" value="${CurrentWeb.Url}"/> 
       <entry key="name" value="SAF Demo Group"/> 
     </dictionary> 
   </property>
</object>

 

By supplying the Action (with its entity) this is equivalent to writing :

STSADM -o deletegroup -url http://localhost -name -“SAF Demo Group".

Note! The “${CurrentWeb.Url}” line, shown in the example, is called a Placeholder and will substitute the value with real “url” at runtime.

That’s pretty much it. You can now call any STSAdm command available by supplying a correct “Operation” and dictionary matching the parameters that the command takes.

Download SAF from http://SAF.Codeplex.com.

Posted on Tuesday, July 28, 2009 6:25 AM | Back to top


Comments on this post: Run STSADM commands from SAF

# re: Run STSADM commands from SAF
Requesting Gravatar...
thanks for articles..
i will download SAF right now
Left by neody on Mar 10, 2011 7:49 PM

Your comment:
 (will show your gravatar)


Copyright © SAF | Powered by: GeeksWithBlogs.net