Jump to content


Mike S

Automated Diskpart Script using Boot Media

Recommended Posts

I have a semi-quick question. How can I implement an automated solution that executes the diskpart command before the TS begins?

 

We maintain quite a few enctrypted laptops in my organization. As a result, no deployments will run until we perform diskpart. I already have a correct script file in place that will automate the commands needed. What I would like is to automate the actual diskpart command. Currently, once I boot using a USB flash drive, I have to press F8 to get the command window, I then have to switch to the root of the flash drive and type diskpart /s diskpart.txt. I would like this process to be automatic once I boot using the flash drive. How can I do this?

 

Thanks,

Mike

Share this post


Link to post
Share on other sites


I would think adding a command line to the start of your Task Sequence would do the trick. Try a test, open your Task Sequence and then click the 'Add' button and select 'General' and then 'Run Command Line.' Under the Command Line in the new entry try the following and see if it works (without the quotes)...

 

"cmd.exe /c diskpart /s diskpart.txt"

 

If the diskpart.txt is not local then you will need to fully qualify the path for this file.

 

Have you tried the partioning tools within the Task Sequence to see if you can get them to do this for you? I use it to create a 1.5 gig partition for the boot files, DaRT, and Bit Locker (if needed in the future) and it works well for me.

 

BTW, why are you using Diskpart? It will not remove any encrypted data so if you run file recovery software it will find a lot of what was on the drive. I work with high security stuff as well but we run Department of Defence Wipe which takes 7 passes of the drive and will remove everything.

Share this post


Link to post
Share on other sites

I have tried that. The problem is that the disk is encrypted and cannot be written to until diskpart is run.

 

What I have to do currently is boot into winPE using the flash drive, press F8 for the command window then manually run the diskpart command.

 

What I wanted to do is boot into winPE, run the diskpart automatically, then continue with the OS deployment.

 

I was able to partially succeed. I mounted the boot.wim from the bootable media and added "run=diskpart /s diskpart.txt" to tsbootshell.ini file located in sms\bin\x64.

WinPE started to load, automatically ran the diskpart command then rebooted the PC. Once the reboot was completed, all that was displayed on the screen was BOOTMGR is missing.

 

Not quite sure yet what I am missing.

 

I use diskpart because it only take a few seconds to complete. It will remove the encrypted disk partitions very nicely. The DoD 7 pass takes far too long to finish.

Share this post


Link to post
Share on other sites

After your TS has run Diskpart are you running a 'Format and Partition Disk' to create the new partition for Windows to be applied to? I set the first command in my TS to restart in Win PE and the next step is to partition the hard disk and then apply Windows to the partition.

Share this post


Link to post
Share on other sites

I must not be wording my posts correctly...

 

The diskpart has to be executed before I can begin execution of the actual OS Task Sequence. Otherwise, the encrypted HDD cannot be written to. This is why i want to execute the diskpart before anything else. There are the steps needed in order:

 

1. Boot from flash drive

2. Run (automatically) diskpart with configuration txt file to remove the encrypted partion and format ntfs

3. When diskpart is finished, winPE starts

4. The Task Sequence Wizard appears.

5. Click the "Next" button

6. Confirmation Window appears

7. OS deployment TS then begins.

 

I have tried to incorporate diskpart into the task sequence without any luck. The encrypted disk prevents the TS .wim file from writing to it. Therefore, diskpart must be executed before winPE actually starts.

Share this post


Link to post
Share on other sites

Someone at my company found this solution but it was because the new PCs had Dell partitions on it that we used it and not because of Pointsec encryption though it wipes that out too.

 

If you mount your boot image using imagex, there's a file called TSconfig.ini, the other files are the ones you will create and add to it but also needs to be in teh same directory as the TSconfig.ini.

 

What I find annoying about this is that if hte Task Sequence fails to find a TS then the hard drive is already wiped clean.

 

You shouldn't need to format the drive from this script, the TS shoudl have a step to format before you apply the image.

 

Here's the contents of each file, underline is the filename and bold is the contents.

 

This executes automatically when the Task Sequence Wizard loads. You'll see dos windows appear and disappear from teh script running.

 

I have incorporated this script as a package and it worked, this was put in at the first step before naming the system and formatting and apply the WIM. You could try this and see if it works with your current TS w/o creating a new boot wim. If anything you would only need the 2 new files and not the TSconfig.ini if you want to make a package. I havent really tested it out with many systems but it worked on all that I tried. If it odesn't work for you then put it on the boot media instead, that definitely works.

 

TSconfig.ini

[CustomHook]

Commandline="x:\PreTS.vbs"

 

PreTS.vbs

Option Explicit

On Error Resume Next

Dim oShell, oFso

Set oShell = CreateObject("WScript.Shell")

Set oFso = CreateObject("Scripting.FileSystemObject")

 

oShell.Run "diskpart.exe /s x:\diskpart.ini",,true

 

Diskpart.ini

select disk=0

 

clean

 

create partition primary

 

select partition=1

 

assign letter=C

 

active

Share this post


Link to post
Share on other sites

Thanks for the detailed info...it looks very promising.

One last question,

I do not have TSconfig.ini in my boot.wim file. Can I simply create one? If so, do I place it in the root of the .wiom file (x:\)?

 

Thanks again,

Mike

Share this post


Link to post
Share on other sites

I have resolved my issue with automating diskpart.

 

I ended up creating a menu-based batch file that runs before the task sequence begins. This way we can run specific diagnostic tools on the disk before the task sequence is initiated.

When finished, the command window is closed and the task sequence runs.

 

To accomplish this, all I did was mount the boot.wim file, then I edited the winpeshl.ini file to load the batch file before TSBootShell.exe.

 

Problem solved.

 

Thanks to all of you who provided me with insight as to where to start.

 

Mike

Share this post


Link to post
Share on other sites

Thanks for the detailed info...it looks very promising.

One last question,

I do not have TSconfig.ini in my boot.wim file. Can I simply create one? If so, do I place it in the root of the .wiom file (x:\)?

 

Thanks again,

Mike

 

Yes, you coudl have just created it.

 

Here's the link to it, it looks like the TSConfig can also be used to save environment variables later on.

 

http://technet.microsoft.com/en-us/library/bb694075.aspx

 

It's good you got it working another way.

Share this post


Link to post
Share on other sites

as this is a useful post i'm going to pin it ! thanks

Share this post


Link to post
Share on other sites

I havent read through all the post.

But im guessing you are after something like this :-)

 

select volume 0 
assign letter=d
select disk 1
online disk noerr
attributes disk clear readonly noerr
clean 
create partition primary noerr
assign letter=e noerr
format FS=NTFS LABEL="Application Volume" QUICK noerr
select disk 2
online disk noerr
attributes disk clear readonly noerr
clean 
create partition primary noerr
assign letter=f noerr
format FS=NTFS LABEL="Database Volume" QUICK noerr
select disk 3
online disk noerr
attributes disk clear readonly noerr
clean 
create partition primary noerr
assign letter=g noerr
format FS=NTFS LABEL="Transaction Volume" QUICK noerr
select disk 4
online disk noerr
attributes disk clear readonly noerr
clean 
create partition primary noerr
assign letter=h noerr
format FS=NTFS LABEL="Bank Volume" QUICK noerr
exit

 

Commandline in task seq:

diskpart /s "%scriptroot%\Custom\DiskPartSCCM.txt

Share this post


Link to post
Share on other sites

Thanks for your valuable reply! :)

i have one more q?

How can format only c: drive except other drive in TS? How to create the TS in MDT?

Share this post


Link to post
Share on other sites

A solution inside the Task Sequence would be to use the format.com command from the x: drive. Since the format command is already in the ram (x:) drive it doesn't required to be copied to the encrypted partition, later if you prefer you can rerun diskpart.

 

Command line: FORMAT.com C: /V:System /FS:NTFS /X /Q /Y

 

Start in: x:\windows\system32

Share this post


Link to post
Share on other sites

Hi how about some settings in you Boot image if you go to the Customisation tab (2012 1511) you can add the following command line

 

cmd /c xcopy.exe *.* X:\ /IERYH & cmd /c Diskpart /S X:\Disk-Part-Clean.txt

 

you will need to add the .txt file on a file share and include the path in the "include files for prestart command"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...