none
Scripts to deploy imagex images RRS feed

  • General discussion

  • Hi all

     

    part of my work at the moment is creating a Windows Vista SOE.

    As you may or may not know Vista and the upcoming Server 2008 use Microsoft's new imaging format wim.

    They have released a tool called imagex to capture, edit and deploy these images.

    Also apparently imagex supports capturing XP, 2000 and 2003 images but I have not tested this.

     

    I wanted to share some of the work I have done so that others can benefit.

    I have never posted in a forum before, but have very often read other forums to find answers I need.

    So its time to give back Smile

     

    The company I am working for gets a separate company to build their computers that go out to customers with a specialised Vista SOE (certain apps etc).

    In the end the computers get added to my company's domain, but we do not want the other company to be part of our domain.

    Because the other company will not have Active Directory we could not use Windows Deployment Services for deployment.

     

    If you are working for a large company that uses Active Directory then I would suggest using Windows Deployment Services, the replacement for RIS. So read no further.

     

    If you are working for a small company or have a situation like mine where a seperate company builds your computers, or you do not have Active Directory, and you want a simple, cheap solution then this may help.

     

    First go and get the Windows Automated Installation Kit (WAIK)

    http://www.microsoft.com/downloads/details.aspx?familyid=C7D4BC6D-15F3-4284-9123-679830D629F2&displaylang=en

    Burn this image to a DVD.

    You can get by with just using WAIK to deploy your imagex (Microsoft's new imaging tool) images, but if you can implement Windows Deployment Services that is a more scalable solution (plus there are some good improvements coming in WDS for Server 2008 like multicasting).

     

    To start you will have to create a master image.

    The following link is a good place to start because it covers the whole process.

    http://download.microsoft.com/download/3/b/a/3ba6d659-6e39-4cd7-b3a2-9c96482f5353/Deploying%20Vista%20Step%20by%20Step%20Guide.doc

     

    After you have your master image you want to deploy it as easily as possible.

    Basically I was looking for some scripts to automate the deployment of Vista from the Windows PE 2.0 environment.

    I could not find any so I wrote some and want to share them.

    You could use these scripts with a Windows PE DVD or UFD and an answer file to deploy the master image.

     

    There are 3 scripts menu.bat, deployimage_localimage.bat, deployimage_networkimage.bat,

    and one text file with diskpart commands.

    I use the abbrevation UFD allot in these scripts which stands for USB Flash Drive.

     

    menu.bat Displays a menu in Windows PE to deploy an imagex image

    deployimage_localimage.bat Deploy an imagex image, with the image being on a UFD or DVD

    deployimage_networkimage.bat Deploy an imagex image, with the image being on a network share

    diskpartcmds.txt Commands to format the first hard-drive

     

    These scripts assume they are all in the same directory and that choice.exe is also in the same directory.

     

    The variables in these scripts could be gathered via the script and therefore not have to be hard-coded.

    While it is possbile to gather the variables in this interactive way it would add complexity to the scripts for a debatable amount of gain.

     

    I HAVE LEFT THE VARIABLES SET TO A VALUE IN THE SCRIPTS TO MAKE IT EASIER TO UNDERSTAND, BUT THESE VARIABLES MUST BE CHANGED TO SUIT YOUR ENVIRONMENT.

    Here are the scripts;

     

    diskpartcmds.txt

     

    Code Snippet

    select disk 0
    clean
    create partition primary
    select partition 1
    active
    format quick
    exit

     

     

     

     

    menu.bat

     

    Code Snippet

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SOE DEPLOY SCRIPT
    ::
    :: Language     Win32/MS-DOS compatible Batch File
    ::
    :: Title menu.bat
    ::
    :: Parent:     
    ::
    :: Purpose:     Displays a menu in Windows PE to deploy an imagex image
    ::
    :: Comments: UFD stands for USB Flash Drive
    ::
    :: Author: Neil Frawley
    ::
    :: Version: 1.0
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @ECHO OFF

    ::VARIABLES
    SET title=DEPLOY IMAGEX IMAGE MENU
    SET script_dir=%0\..


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Display Title
    cls
    ECHO %title%
    ECHO.

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Menu
    ECHO Press the number to select the option
    ECHO.
    ECHO 1) DEPLOY IMAGEX IMAGE, IMAGE ON UFD OR DVD
    ECHO 2) DEPLOY IMAGEX IMAGE, IMAGE ON NETWORK SHARE
    ECHO.

    %script_dir%\choice /C:12

    ECHO.
    IF ERRORLEVEL 2 GOTO :NETWORK
    IF ERRORLEVEL 1 GOTO :LOCAL

    :LOCAL
    %script_dir%\deployimage_localimage.bat
    goto END

    :NETWORK
    %script_dir%\deployimage_networkimage.bat
    goto END

     

    :END

     

     

     

    deployimage_localimage.bat

     

    Code Snippet

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SOE DEPLOY SCRIPT
    ::
    :: Language     Win32/MS-DOS compatible Batch File
    ::
    :: Title deployimage_localimage.bat
    ::
    :: Parent: menu.bat
    ::
    :: Purpose:     Deploy an imagex image, with the image being on a UFD or DVD
    ::
    :: Comments: UFD stands for USB Flash Drive
    ::  This script could be run from a CD instead of a DVD, but it is unlikely the imagex image will fit on a CD
    ::
    :: Author: Neil Frawley
    ::
    :: Version: 1.0
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @ECHO OFF

    ::VARIABLES
    SET title=DEPLOY IMAGEX IMAGE, IMAGE ON DVD OR UFD
    SET script_dir=%0\..

     

    SET diskpart_script=diskpartcmds.txt
    SET local_drive=C:
    SET image_name=master_soe.wim


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Display Title
    cls
    ECHO %title%
    ECHO.

    ECHO Press the number to select the option
    ECHO.
    ECHO 1) I AM USING A UFD
    ECHO 2) I AM USING A DVD

    ECHO.

    %script_dir%\choice /C:12

    IF ERRORLEVEL 2 GOTO :DVD
    IF ERRORLEVEL 1 GOTO :UFD


    :UFD
    SET tools_drive=E:
    SET image_path=E:\images
    ECHO WinPE run from UFD
    GOTO :PREP

    :DVD
    SET tools_drive=D:
    SET image_path=D:\images
    ECHO WinPE run from DVD
    GOTO :PREP

     

    :PREP
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Prepare hard-drive
    ECHO **** PREPARE HARDDRIVE ****
    ECHO.
    %script_dir%\choice /M "diskpart will now wipe the contents of your hard-drive erasing all data. Do you wish to continue?"
    IF ERRORLEVEL 2 GOTO :END
    diskpart /s %script_dir%\%diskpart_script%

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Apply Image to hard-drive
    ECHO **** APPLY IMAGE ****
    %tools_drive%\tools\imagex.exe /apply %image_path%\%image_name% 1 %local_drive%

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Reboot computer
    ECHO Please insert a UFD containing unattend.xml at the root of the drive.
    ECHO When you are ready to reboot the computer,
    pause
    ECHO **** REBOOT ****
    wpeutil reboot

     

    :END

     

     

     

    deployimage_networkimage.bat

     

    Code Snippet

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SOE DEPLOY SCRIPT
    ::
    :: Language     Win32/MS-DOS compatible Batch File
    ::
    :: Title deployimage_networkimage.bat
    ::
    :: Parent:      menu.bat
    ::
    :: Purpose:     Deploy an imagex image, with the image being on a network share
    ::
    :: Comments: UFD stands for USB Flash Drive
    ::
    :: Version: 1.0
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    @ECHO OFF

    ::VARIABLES
    SET title=DEPLOY IMAGEX IMAGE, IMAGE ON NETWORK SHARE
    SET script_dir=%0\..

     

    SET diskpart_script=diskpartcmds.txt
    SET local_drive=C:
    SET image_name=master_soe.wim

     

    SET mapped_drive=Y:
    SET server_share=soe_vista
    SET user_share=svcWAIK
    SET user_share_pwd=Passw0rd
    SET server_ip=192.168.150.10
    :: server_ip can also be the server name if DNS is available


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Display Title
    cls
    ECHO %title%
    ECHO.


    ECHO Press the number to select the option
    ECHO.
    ECHO 1) I AM USING A UFD
    ECHO 2) I AM USING A DVD

    ECHO.

    %script_dir%\choice /C:12

    IF ERRORLEVEL 2 GOTO :DVD
    IF ERRORLEVEL 1 GOTO :UFD


    :UFD
    SET tools_drive=E:
    SET image_path=E:\images
    ECHO WinPE run from UFD
    GOTO :PREP

    :DVD
    SET tools_drive=D:
    SET image_path=D:\images
    ECHO WinPE run from DVD
    GOTO :PREP

     

    :PREP
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Prepare hard-drive
    ECHO **** PREPARE HARDDRIVE ****
    ECHO.
    %script_dir%\choice /M "diskpart will now wipe the contents of your hard-drive erasing all data. Do you wish to continue?"
    IF ERRORLEVEL 2 GOTO :END
    diskpart /s %script_dir%\%diskpart_script%


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Map drive to network share
    ECHO **** MAP DRIVE NETWORK SHARE ****
    net use %mapped_drive%
    \\%server_ip%\%server_share% /USER:%server_ip%\%user_share% %user_share_pwd%

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Copy image from network share to local drive
    ECHO **** COPY IMAGE FROM NETWORK TO LOCAL ****
    copy %mapped_drive%\%image_name% %local_drive%

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Apply Image to hard-drive
    ECHO **** APPLY IMAGE ****
    %tools_drive%\tools\imagex.exe /apply %local_drive%\%image_name% 1 %local_drive%

     

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Delete Image from hard-drive
    ECHO **** DELETE LOCAL IMAGE ****
    del %local_drive%\%image_name%


    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: SECTION: Reboot computer
    ECHO Please insert a UFD containing unattend.xml at the root of the drive.
    ECHO When you are ready to reboot the computer,
    pause
    ECHO **** REBOOT ****
    wpeutil reboot

     

    :END

     

     


     

    THESE SCRIPTS REQUIRE CHOICE.EXE TO BE IN THE SAME DIRECTORY AS THE SCRIPTS.

    YOU CAN FIND CHOICE.EXE ON A WINDOWS SERVER 2003 BOX AT C:\WINDOWS\SYSTEM32

     

    In my Windows PE environment I have a 'scripts' folder containing these scripts and choice.exe.

    I also create a folder named 'images' in my Windows PE environment and place my imagex image in that.

    So once Windows PE loads I enter the command

    E:\scripts\menu (if booting from UFD)

    D:\scripts\menu (if booting from DVD)

     

    I suggest having a DHCP device in your environment to give the destination computer an IP address otherwise you would have to assign one in Windows PE.

     

    So there you have it. If you have any questions feel free to post back.

    If you edit these scripts so that they don't use hard coded variables then please post back because I will use them.

    I wish I could have uploaded these scripts so they could be downloaded but not sure how.

     

    Disclaimer: I am not a programmer so these scripts are far from elegant, but they do the job.

    Any feedback is welcome because I will be using these scripts.

     

    Neil.

    Friday, September 14, 2007 6:11 AM

All replies