Posts Tagged ‘Batch Script’

Run only scripts that you trust. Disable Powershell Message

Monday, October 26th, 2009

This article can also be read at my new website: http://www.theitbros.com.

If you are like me you have probably run into the following error when trying to run powershell scripts. This becomes very annoying and tedious if you are running different scripts on a regular basis.

“Security Warning – Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run –.ps1? [D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

Step #1

The first thing you need to do is launch Windows Powershell.

Step #2

Then enter the following commands:

get-executionpolicy

set-executionpolicy bypass

Powershell Trust Scripts

Powershell Trust Scripts

Now launch your script and enjoy not seeing that annoying message come up.

How to Capture and Deploy Image (.wim) Without Sysprep

Saturday, August 8th, 2009

If you are using WinPE 2.0 or WinPE 3.0 to capture your PC images (.wim files) and deploy them you have probably run into a little problem when trying to deploy an image of Vista or Windows 7 when not first running sysprep. The problem is that if you try to re-deploy an image of a nonsysprepped image of Vista or 7 that the BootMGR will be broken. Follow the steps below to fix this problem.
Microsoft Windows 7

Step #1

I am assuming you have captured your image already and are ready for deployment. Go ahead and boot up your image deployment software (WinPE 2.0 or WinPE 3.0).

Step #2

In my other articles I describe how to use DiskPart and also avoiding the hidden partition before deploying a new image. I suggest reading them.

Step #3

After you have deployed your non-sysprepped image you need to run the following commands: (I have a batch file I use to do this).

bcdedit /set {default} device partition=c:
bcdedit /set {default} osdevice partition=c:
bcdedit /set {bootmgr} device partition=c:

Step #4

This will fix the BOOTMGR problem when deploying a non-syprepped image in Vista or 7. Enjoy!

Deployment Image Servicing and Management (DISM) – WinPE 3.0 Boot Environment

Friday, June 19th, 2009

I recently compiled a new library of commands since the upgrade from WinPE 2.0 to WinPE 3.0. With Windows 7 coming along they released a new way to create bootable USB sticks using Deployment Image Servicing and Management (DISM.exe). You might be asking yourself, what could I use this for? We are using it at my work to re-image computers, capture backup images, mount images, etc. There are many other uses for it but I will not get into that here. I have literally done this procedure a couple hundred times. In a future article I will show you how to write a simple batch script to automate this process. But it helps to understand what is going on with each command in case you have trouble. Batch scripts never work 100% of the time.

You will need the following to proceed:
Windows® Automated Installation Kit (AIK) for Windows® 7 RC (Download from Microsoft) : 05.01.09

  • Windows® Automated Installation Kit (AIK) for Windows® 7 RC (Download from Microsoft) : 08.06.09
  • Bootable Flash drive (500MB or larger)
  • Once you have installed WAIK then you will need to browse to your start menu and click on “Deployment Tools Command Prompt”. I have provided a picture below.

    DISM

    DISM

    Once you have launched DTCP you will need to follow through the commands I have compiled below. The first one I have provided a screenshot.

    DISM – Step #1 – Prep/Cleanup

    DISM /Cleanup-Wim

    The DISM cleanup command simply cleans up any previous wims/mounts you have been working with. If you do this a lot, you will need to use this command otherwise you will start receiving errors from previous wims possibly still left on the system.

    DISM Step #1

    DISM Step #1

    DISM – Step #2 – Copy WinPE 3.0 to your local C Drive

    copype.cmd x86 c:\winpe_x86
    copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim

    This creates a winpe_x86 folder on your C: drive and then copies the contents of the WinPE folder from the WAIK installation to your folder.

    DISM – Step #3 – Mounting .Wim File on your local C Drive

    Dism /Mount-Wim /WimFile:C:\winpe_x86\winpe.wim /index:1 /MountDir:C:\winpe_x86\mount

    This command mounts the wim file that was copied over in step #2 so that you can browse the system32 folder and insert your custom scripts, etc.

    DISM – Step #4 – Adding Packages to your WIM

    Dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:”C:\Program Files\Windows AIK\Tools\PETools\x86\WinPE_FPs\winpe-wmi.cab”
    Dism /image:C:\winpe_x86\mount /Add-Package /PackagePath:”C:\Program Files\Windows AIK\Tools\PETools\x86\WinPE_FPs\en-us\winpe-wmi_en-us.cab”

    There are many packages you can add to your WINPE boot environment, these are two I always add to mine.

    DISM – Step #5 – Adding Drivers to WinPE

    DISM /image:c:\winpe_x86\mount /Add-Driver /driver:C:\YOUR_FOLDER_OF_INF_DRIVERS\ /recurse

    A nice addition to DISM over the previous peimg command in WINPE 2.0 is the ability to add drivers with the /recurse command. The /recurse command now allows us to simply have all of our drivers in their own directory and tell DISM to scan the root folder and everything beneath it. The number of sub directories won’t matter. I have a huge library of drivers, for example, you will want to have the network and vga drivers for anything that you boot up to in the WinPE environment. By adding the network driver to your WinPE boot environment, it allows you to access network shares for capturing and deploying .wim images.

    DISM – Step #6 – Adding Custom Scripts, Batch Files, Etc.

    xcopy /e /y “C:\YOUR_FOLDER_OF_SCRIPTS” C:\winpe_x86\mount\Windows\System32\

    Without adding anything to your WinPE boot environment you will simply be left with a command prompt window when booting to it on a computer. I have added over 15 different batch scripts with different functions. Click here to download my WinPE discs. One thing I highly suggest adding is GImageX. GImageX is a very small GUI program that you can add to be able to capture, deploy, and mount images within the WinPE boot environment. I have provided a picture of GImageX GUI below.

    For WinPE 3.0 Boot Environment - Mount, Deploy, Capture Images

    For WinPE 3.0 Boot Environment - Mount, Deploy, Capture Images

    DISM – Step #7 – Unmounting your finished .WIM

    Dism /Unmount-Wim /MountDir:C:\winpe_x86\mount\ /Commit

    This commits the final changes to your .WIM file and anything you added to it. It is very important to unmount your .WIM file when you have finished.

    DISM – Step #8 – Copies your .WIM to Boot ISO

    copy c:\winpe_x86\winpe.wim c:\winpe_x86\ISO\sources\boot.wim /Y

    DISM – Step #9 – Creates bootable .ISO of WinPE 3.0

    oscdimg -n -bc:\winpe_x86\etfsboot.com c:\winpe_x86\ISO c:\winpe_x86\winpe_x86.iso

    Now, if you are wanting to use a flash stick you will need to format a flash stick in a certain way, and then simply copy the contents of the c:\winpe_x86\ISO\ to your flash drive. And thats it! Stick it in a computer, restart, and boot to it. The .ISO made in step #9 can simply be burned to a CD with Nero or other program capable of making bootable CD and then you can boot to it in the same way.

    DISM – Step #10 – Optional Backup

    xcopy /e /y “C:\winpe_x86″ E:\BACKUP_FOLDER_FOR_LATEST_BOOT_BUILD\

    This step is optional, but I always like to keep a backup for the future. Also, if you ever need to create another bootable flash stick or CD you can simply go to your backup and grab the files.

    Java 1.6.0.12 .msi package for distribution

    Thursday, February 19th, 2009

    Last msi package I tested today was Java. They also offer the msi package on their website. First you need to download their “offline installation” executable here. Then run the executable but don’t go through any additional prompts. Navigate to LocalAppData folder (the user’s Application Data folder). The location of the LocalAppData folder differs for each Windows platform.

    * Windows Vista: C:\Users\\AppData\LocalLow\Sun\Java\jre1.6.0_12
    * Windows XP: C:\Documents and Settings\\Local Settings\Application Data
    * Windows 2000 C:\Documents and Settings\\Application Data

    Copy the contents out of that folder to where you are keeping your msi distribution packages. The folder should look like the picture below without the install.bat which is my batch file.

    Java Directory Contents

    Java Directory Contents

    Here is the command I used for a quiet install for multiple users:

    msiexec /i "jre1.6.0_12.msi" SETMULTIUSER=1 /qb"

    Works fine for multiple users under windows 2000, XP, and Vista. More MSI package instructions coming tomorrow along with some tutorials on ImageX/Sysprep for Vista.

    Java 1.6 Logo

    Java 1.6 Logo

    Batch Script – Backup folder over network

    Monday, January 19th, 2009

    Here is a batch script I use to make a backup of my laptop. I have it backing up multiple folders, but here is example of backing up a laptop folder (My Thunderbird Profile) to a networked computer share. Will work both ways.

    for /f “tokens=2-4 delims=/ ” %%g in (‘date /t’) do (
    set mm=%%g
    set dd=%%h
    set yy=%%i
    )

    if exist “\\IPADDESS\c$\Users\Administrator\Documents\My Laptop Backups\%mm%-%dd%-%yy%” (
    rd /S /Q “\\IPADDRESS\c$\Users\Administrator\Documents\My Laptop Backups\%mm%-%dd%-%yy%”
    )

    xcopy “C:\Users\Administrator\AppData\Roaming\Thunderbird\Profiles”
    “\\IPADDRESS\c$\Users\Administrator\Documents\My Laptop Backups\%mm%-%dd%-%yy%” /s /i