Skip to content

Ludo's LRT blog

just another Learning and Research Technologies weblog

Archive

Tag: regex

This is a “reprint” of an article originally published on a private wiki not open to the public by me in July 2009.

Add & Deploy
To install a SharePoint solution called solution.wsp from C:\MMU Web Parts\ on your SharePoint farm (you should be able to run these commands from any web server in the farm):

Add:
stsadm -o addsolution -filename "C:\MMU Web Parts\solution.wsp"

Now deploy it to the web application of your SharePoint site:

Deploy:
stsadm -o deploysolution -name "solution.wsp" -url "https://my.mmu.ac.uk" -immediate [-allowgacdeployment]

Enumerate current solutions

If you’d just like to see which solutions are installed on your SharePoint server farm:

stsadm -o enumsolutions

But this spits out a lot of XML that’s very difficult to read on the command line (or at all). Here’s a Perl script to run to get enumsolutions without all the surrounding flim-flam:

@o=split /</,`stsadm -o enumsolutions`;
while(<@o>){
chop;
print qq[$_\n] if /^Name=.*wsp/;
}

or on the Windows cmd line:

perl -e "@o=split /</,`stsadm -o enumsolutions`; while(<@o>){chop;print qq[$_\n] if /^Name=.*wsp/;}"

Retract & Delete

To uninstall a SharePoint solution from your farm run both of these commands:

stsadm -o retractsolution -name "solution.wsp" -url "https://my.mmu.ac.uk" -immediate

stsadm -o deletesolution -name "solution.wsp"

Lastly, here’s an improved Perl one-liner for taming the tidal wave of XML output from enumsolutions.

If your job includes looking after a Microsoft SharePoint server or server farm and you’re interested in scripting and command line shenanigans, then you’ll almost certainly be familiar with stsadm, the collection of utilities that allow you to run or script SharePoint operations from the command line instead of using the web interfaces.

If you’re a SharePoint developer then you may have used stsadm’s addsolution, retractsolution, deploysolution and deletesolution operations to install and uninstall features (such as web parts – SharePoint terminology for widgets) on your server or farm too.

What about those times when you want to see which solutions you already have installed? Perhaps you can’t add a solution, so you want to see if it’s already on the server. You need the ‘enumsolutions’ command.

Unlike the four commands above, which have fairly terse output such as ‘Operation completed successfully’, the enumsolutions operation spits out a huge screed of XML that’s a pain to read through, especially on the command line.

I came up with a fairly complicated-looking Perl one-liner to run at the command line next to the stsadm commands on their own to just get back the bits of the XML I was interested in over a year ago on a not publicly accessible wiki.

Here is the whole article ‘reprinted’.

Anyway, that was my first go, in July 2009. Here’s a much pithier Perl one-liner to return the solutions installed in your SharePoint farm. This script just returns a neat list of the individual solutions that are installed on your SharePoint farm:-

perl -e "print(grep {/<Solution Name=.*>/} `stsadm -o enumsolutions`);"

A little extension to the regex could also give you the deployment status but I don’t have time to get that working right now. This is a very simple regex.

Note: all of these commands work on the version of SharePoint known as MOSS 2007. I don’t know how much stsadm has changed for SharePoint 2010 or whether it was very different in SharePoint 2003.