locked
stsadm operation automation question

    Question

  • I want to automate some stsadm tasks - some manually initiated, some I might put on a schedule. I'm hoping someone can help me out here.

    Here's what I want to accomplish: 

    1) Retrieve a list of web apps from a farm
    2) enum site collections in each web app
    3) Run stsadm operations on each site collection in the resulting list

    I am willing to manually update a file (not sure what file type or format) with the web apps list.
    I know I can dump the results of an enumsites to an xml file, but don't know how to retrieve that info and insert it into a stsadm command.

    I would prefer suggestions using either VBScript or PowerShell as I don't have great skill at C# or VB.Net and want to be able to expand on these ideas in the future.

    Anyone want to take a crack at this one for me?

    Thanks.

    Kevin Hughes
    SharePoint Database Administrator
    HNTB Companies
    Friday, August 22, 2008 1:39 PM

Answers

  • Hi Kevin,

    I posted a script a few weeks ago that might be useful:

    You can download it from here:

    http://james.milne.com/scripts/SiteWalker.zip

    Inside you will find a script called WalkSites.vbs.  In a nutshell it does a STSAdm command to dump the site collections to a sites.xml file then it loops through each one and then executes a STSAdm Export command on each site collection.  You can tweak the vbs to get it to run pretty much any command against each site.

    Hope this helps,

    Regards,
    James.
    • Marked as answer by Kevin Hughes Wednesday, August 27, 2008 3:06 PM
    Monday, August 25, 2008 3:38 PM

All replies

  • To me... this is sounding more like a windows service than a script.  The code to do this is actually quite simple if you have even a little C# or VB.NET skills.

    You can probably find great examples on the following objects to help along the way: SPSite, SPWeb, SPList

    These objects are pretty simple to use.  If you decide to go this route and need a couple of resources, let me know.
    Shannon Bray - MCT, MCPD, MCTS, MCITP
    Saturday, August 23, 2008 1:09 AM
  • It really just depends on what your goals are (what is that you are wanting to do with each site collection?).  PowerShell may be the way to go as it's a lot easier to build and customize and deploy than a windows service (not that a windows service is difficult but if you already have powershell experience that will get you going quicker).  Another option would be to build your own stsadm command (would require some c# experience) - there's a codeplex project that I've got that will help get you started if you go this route: http://www.codeplex.com/customstsadmtemplate or you can download my extensions from here: http://stsadm.blogspot.com - it's possible I may already have something that does what you need.
    Saturday, August 23, 2008 6:22 PM
  • Hi, 

    Here are some useful PowerShell articles and a command pack for your reference:

    1.    Managing SharePoint with PowerShell, Part 1 (http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=7)

    2.    Managing SharePoint with PowerShell: Part 2 (http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=21)

    3.    PowerShell Pack for SharePoint (http://code.msdn.microsoft.com/psp4sp)

     

    However, this is not the best place to discuss programming issues, so If the information cannot satisfy you, I can help you move to the SharePoint - Development and Programming.

     

    Hope the information can be helpful.

    -lambert


    Posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, August 25, 2008 7:34 AM
  • Kevin,

    Please refer to this blog post http://spadmin.spaces.live.com/Blog/cns!F030C52B8E5517C3!347.entry

    This shows you how to make use of BAT file which takes input from text files and then does some processing using stsadm for each line of input from text file.

    This is very poweful and i have used it for lot of automation tasks.


    Sameer Dhoot | http://sharemypoint.in
    Monday, August 25, 2008 2:13 PM
  • Hi Kevin,

    I posted a script a few weeks ago that might be useful:

    You can download it from here:

    http://james.milne.com/scripts/SiteWalker.zip

    Inside you will find a script called WalkSites.vbs.  In a nutshell it does a STSAdm command to dump the site collections to a sites.xml file then it loops through each one and then executes a STSAdm Export command on each site collection.  You can tweak the vbs to get it to run pretty much any command against each site.

    Hope this helps,

    Regards,
    James.
    • Marked as answer by Kevin Hughes Wednesday, August 27, 2008 3:06 PM
    Monday, August 25, 2008 3:38 PM
  • Gary,

    I use the STSADM extensions you built very often. Thank you so much for all the work put into them.
    I didn't see anything in your selection, though, that would do what I needed.

    I am a poor coder when it comes to C# and VB.Net, but do quite well with VBScript and PowerShell (long-time sysadmin who liked to automate). I also need to be able to pass this on to other members of our SharePoint Ops team that are even less savy with coding than I am.

    I understand the code you wrote, but could not duplicate it.
    Wednesday, August 27, 2008 3:09 PM
  • Lambert,

    Thank you for the PowerShell links. I love PowerShell, so will probably use as much of what you've refereced as I can.
    The only issue with it is that my manager doesn't know PowerShell, so not sure how he'll receive it if I work in it. Oh well....will make life easier for a bit.

    Wednesday, August 27, 2008 3:29 PM
  • Kevin,

    Just being curious, how do u retrieve a list of web apps from a farm?

    Use the following example to read from an XML.


    Thanks,

    Ruben

    Option Explicit
    
    Const SITE_URL = "http://myurl/"
    
    Const STSADM = "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm"
    
     
    
    dim objShell
    
    dim objExec
    
    dim strResult
    
    dim objXml
    
    dim objSc
    
    dim objUrl
    
    dim strCmd
    
     
    
    Set objShell = CreateObject("WScript.Shell")
    
    Set objExec = objShell.Exec(STSADM & " -o enumsites -url " & SITE_URL)
    
    strResult = objExec.StdOut.ReadAll
    
     
    
    Set objXml = CreateObject("MSXML2.DOMDocument")
    
    objXml.LoadXML(strResult) 
    
     
    
    For Each objSc in objXml.DocumentElement.ChildNodes
    
        strUrl = objSc.Attributes.GetNamedItem("Url").Text
    
        ‘now u have the value from the node “Url” into strUrl ;)
    
    Next
    

     

    Friday, October 16, 2009 2:41 PM