Monday, May 10, 2010

Batch Feature Installation w/ Logging (Expanded)

Michael Greene wrote an excellent script earlier today.  Since I like to try what I see, I took the script a bit further and added a bit more of logic.  You can see the original script here Batch Feature Installation w/ Logging.  I’ve added more logic to the URL input, EVENTCREATE, and it’ll install every .wsp that you have in the directory.  Here’s how to use this script:

  1. Copy and paste the script into a batch file
  2. Place the batch file in the directory that has all of your .wsp’s
  3. Run the batch file and type the URL of the Site Collection (don’t worry if you mistype the http:// portion of the URL, I have an error checker for that ;-) )

So what will this do? Add the solution(s), deploy the solution(s), install them, and activate all of them in one fell swoop.  Cool eh?  Great for deployment scenarios or setting up those test box vm’s.  Feel free to add more… As I’m posting this, I already have thought of a way to bulk add .stp’s.  Maybe another post?

@echo off
setlocal enabledelayedexpansion
color 0E
Title Auto .wsp Deploy
rem *******************  Deploys all .wsp's in the current directory to the Site Collection ***************************
rem ******************* How to use?  Put this batch file in the same directory as your .wsp's *********************
rem ******************* The script will find every .wsp and deploy it to the Site Collection of your choice ********
rem ******************* I guarantee this will destroy your sharepoint farm unless you know what this ***********
rem ******************* code does.  Please make sure you test this before production usage. *********************
rem ****************** Sets vars *********************************************************************************************
set "path=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\;%PATH%"
set _http=http://
set /P _inputURL="Please enter the url the site collection to activate the feature(s) to: "
rem ******************* Checks the URL and appends http:// if needed **************************************************
IF /I %_inputURL:~0,7% == %_http% (
echo URL is in correct format
set _URL=%_inputURL%
) ELSE (
set _URL=%_http%!_inputURL!
Echo ************* Finding .wsp files *************
for %%a in (*.wsp) do call :ROUTINE "%%a"
Echo Adding Solution
stsadm.exe -o addsolution -filename %1
Echo Deploying Solution
stsadm.exe -o deploysolution -name %1 -allowGacDeployment -immediate -force
Echo Installing Feature
stsadm.exe -o installfeature -name %~n1 -force
IF errorlevel == 0 (
EVENTCREATE /L System /T Success /SO "SharePoint" /ID 3 /D "%1 Installed"
) else (
EVENTCREATE /L System /T Error /SO "SharePoint" /ID 3 /D "%1 didn't install properly"
Echo Activating Feature
stsadm.exe -o activatefeature -name %~n1 -url %_URL% -force
IF errorlevel == 0 (
EVENTCREATE /L System /T Success /SO "SharePoint" /ID 4 /D "%1 Activated"
Echo Activation of feature %1 COMPLETE!
) else (
EVENTCREATE /L System /T Error /SO "SharePoint" /ID 4 /D "%1 didn't activate properly"
echo Running timer jobs to finish deployment
stsadm.exe -o  execadmsvcjobs
PING -n 12 -w 100 2>NUL | FIND "TTL=" >NUL

You can also copy the script from this link: Batch Feature Installation w/ Logging (Expanded)

No comments: