Wednesday, March 13, 2013

Batch File install.bat to automate STSADM–wsp deployment

Batch File to automate STSADM – wsp deployment

Open a notepad and add the below lines and save as Install.bat(extension as dot bat).

Rem == Batch file for SharePoint deployment
@echo off
Rem //---------------------------------------------
@SET STSADM="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\stsadm.exe"

goto menu

:menu
cls
Echo =============== Menu ============================
echo.
echo What would you like to do?
echo.
echo Choice
echo.
echo 1 Restore from Site Backup
echo 2 Add New WSP
echo 3 Deploy WSP
echo 4 Retract WSP
echo 5 Delete WSP
echo 6 Deployment Status Check
echo 7 Open SharePoint Site (after operations)
echo 8 Quit
echo.

:choice
set /P C=[1,2,3,4,5,6,7,8]?
if "%C%"=="8" goto quit
if "%C%"=="7" goto opensite
if "%C%"=="6" goto deploymentStatusCheck
if "%C%"=="5" goto deletewsp
if "%C%"=="4" goto retractwsp
if "%C%"=="3" goto deploywsp
if "%C%"=="2" goto addwsp
if "%C%"=="1" goto restore
goto choice


:restore
Echo Starting Site Restore
Echo Please enter the site url
Set /p url=
Echo You have entered url as:
Echo %url%
Echo Please enter the filename [file path where backup file resides]
Set /p filename=
Echo You have entered the file path as:
Echo %filename%
Echo Please check your inputs
pause

Echo Site Restore Starting.....
%STSADM% -o restore -url "%url%" -filename "%filename%" -overwrite
Echo Site restore complete....
Pause
goto menu

Rem ---------------------------
:addwsp
Echo Please enter the filename [file with path where file resides]
Set /p filename=
Echo Please check your inputs
pause

Echo Add solution.........
%STSADM% -o addsolution -filename "%filename%"
Echo Add solution complete.....
pause
goto menu
Rem ---------------------------

Rem ---------------------------
:deploywsp
Echo Please enter the name of soltuion
Set /p name=
Echo Please enter the site url
Set /p url=
Echo Please check your inputs
pause

Echo Deploy solution.........
%STSADM% -o deploysolution -name "%name%" -url "%url%" -immediate -allowgacdeployment
Echo Deploy solution complete.....
pause
goto menu
Rem ---------------------------

Rem ---------------------------
:retractwsp
Echo Please enter the name of soltuion
Set /p name=
Echo Please enter the site url
Set /p url=
Echo Please check your inputs
pause

Echo Solution retract Starting.....
%STSADM% -o retractsolution -name "%name%" -url "%url%" -immediate
Echo Solution retract complete..........
pause
goto menu
Rem ---------------------------

Rem ---------------------------
:deletewsp
Echo Please enter the name of soltuion
Set /p name=
Echo Please check your inputs
pause

Echo Delete Solution.........
%STSADM% -o deletesolution -name "%name%"
Echo Delete solution complete.....
pause
goto menu
Rem ---------------------------

Rem ---------------------------
:deploymentStatusCheck
Echo Check for the Count.. If only Count is 0 then deployment is complete
%STSADM% -o enumdeployments
pause
goto menu
Rem ---------------------------

Rem ---------------------------
:opensite
start iexplore.exe %url%
pause
goto menu
Rem ---------------------------

:quit
exit
:end

Rem =============================================

No comments:

Post a Comment