次の方法で共有


Creating SharePoint webs with Excel and STSADM

This is a follow-up to my Site Definition Helper scripts post.  As described in that post, we were looking at making it simple to create multiple webs.  While you can use a site definition with a PortalProvisioningProvider to do this, if you have variations, you cannot use it since most of your webs will be under a variation and the provider doesn't create variations.

 

Before we were using Site Definitions, we had a nice STSADM extension that was creating webs + pages, repairing what it needed such as AvailablePageLayouts and WelcomePage parameters.  Fortunately, a good Site Definition design made that obsolete except for creating the "starting webs" as well as for creating test pages (but you could still provision the test pages with a Site Definition anyway).  Since we have Site Definitions, we should use the "STSADM -o CreateWeb" command since it's easy to use and it works fine.

 

The command requires the following parameters:

  • url
  • sitetemplate
  • title
  • lcid

 

Ideally, it would be nice to have a nice Excel file that contains all of these in a much nicer table format than what you would get in a CMD file.  And that's exactly what we did!  The Excel contains the same columns that are required for the command to execute, we export it to an "Text (MS-DOS)" format (very important if you want your locale to work correctly), and then run a "For" loop in a CMD file that reads the exported TXT file :

 

    1: FOR /F "eol=; tokens=1,2,3,4 delims=    " %%i IN (Data/CreateWebs.txt) DO (
    2:     @ECHO ----[ Creating "%%i" ]--
    3:     %stsadm% -o createweb -url %url%%%i -sitetemplate %%j -title "%%k" -lcid %%l
    4: )
    5:  

 

Here's the complete script which requires the variable.cmd available on this post:

    1: @ECHO OFF
    2: cd /d %0\.. 
    3:  
    4: @CALL Variables.cmd
    5:  
    6: @ECHO %separator%
    7: @ECHO Create Website Structure and Content.
    8: @ECHO %separator%
    9:  
   10: :CREATEWEBS
   11: @ECHO:
   12: @ECHO %separator%
   13: @ECHO Create Site Structure
   14: @ECHO %separator%
   15: @ECHO.
   16:  
   17: FOR /F "eol=; tokens=1,2,3,4 delims=    " %%i IN (Data/CreateWebs.txt) DO (
   18:     @ECHO ----[ Creating "%%i" ]--
   19:     %stsadm% -o createweb -url %url%%%i -sitetemplate %%j -title "%%k" -lcid %%l
   20: )
   21:  
   22:  
   23: :IE
   24: @ECHO %separator%
   25: @ECHO Operation completed
   26: @ECHO %separator%
   27:  
   28: IF NOT "%1"=="noie" start iexplore %url%

 

You can download all the scripts here :

 

 

Big thanks to Cristian Deschamps from Orckestra for the help on this.  Happy web creation!

 

Maxime

Comments