Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Using DISKPART in a script

5 posts in this topic

Hoping someone can help me out.

I'm trying to install WindowsXP 64 bit unattended using WindowsPE and want to partition the HD with 1 partition with 30GB and the rest of the disk with the remaining space.

The trouble I'm having is that the computers vary in configuration. Some have a card reader which WindowsPE sees as a disk (or at least DISKPART does).

The disk number varies so I'd like to use a script which reads the first available online disk (some of the computers have 2 disks) and remove all existing partitions and create a 30GB partition and a second one with the remaining space.

Does anyone know how to do this?

Thanks in advance.


Share this post

Link to post
Share on other sites

yes easy:

Launch: diskpart /s diskpart.script

and in your diskpart.script something like:

select disk 0
create partition primary size=30000
assign letter=c
create partition primary
assign letter=d

Edited by hj_fr

Share this post

Link to post
Share on other sites

I see where you're coming from - I had a similar problem when I wanted to use diskpart to change the drive letter of the CDROM drive. I couldn't guarantee which volume it would be. In the end I put together a short VBS script. Use a script to identify which drive it is you want to change. Remember you can use drive letters when specifying the volume in diskpart. With the same vbs script, write out a diskpart.txt script that is specific to that machine, then use the method mentioned above to call it.

Here is how I managed to get this working for a cdrom:

Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

Set CDRoms = FileSystemObject.Drives

Set wshShell = WScript.CreateObject ("WScript.shell")

Dim DVDDriveLetter

For Each CDDrive in CDRoms

If CDDrive.drivetype = "4" Then

DVDDriveLetter = CDDrive.driveletter

End If


Set objTextStream = FileSystemObject.OpenTextFile("C:\diskpart.txt", 2, True)

objTextStream.WriteLine "SELECT VOLUME " & DVDDriveLetter

objTextStream.WriteLine "ASSIGN LETTER=Z"

objTextStream.WriteLine "EXIT"


Set CDRoms = nothing

Set FileSystemObject = nothing

set wshshell = nothing

You could use a similar method to check for a file you know is on the disk you want to change.

Edited by mallen

Share this post

Link to post
Share on other sites

I do something for my vmware builds to make sure the alignment is correct

I found part of this online but added some of the stuff I was already doing to it.

The volume labels you can change this does up to 4 drives and changes the cdrom drive to z:

@echo off

rem Create and Format partition(s)

rem first assign the cdrom drive to z:


rem Create Diskpart Script

echo select disk 0 >"c:\source\scripts\part.txt"

echo select volume d >>"c:\source\scripts\part.txt"

echo assign letter Z noerr >>"c:\source\scripts\part.txt"

rem change cdrom drive letter Partition

DiskPart /s "c:\source\scripts\part.txt"


echo select disk 1 > "c:\source\scripts\part.txt"

echo create partition primary align=64 >>"c:\source\scripts\part.txt"

echo assign letter=D >>"c:\source\scripts\part.txt"

echo active >>"c:\source\scripts\part.txt"

rem Create Partition

DiskPart /s "c:\source\scripts\part.txt"

format D: /FS:NTFS /V:ddrive /q /A:32K /y


echo select disk 2 >"c:\source\scripts\part.txt"

echo create partition primary align=64 >>"c:\source\scripts\part.txt"

echo assign letter=E >>"c:\source\scripts\part.txt"

echo active >>"c:\source\scripts\part.txt"

Rem creating partition

DiskPart /s "c:\source\scripts\part.txt"

rem Format Partition

format E: /FS:NTFS /V:edrive /q /A:32K /y


echo select disk 3 >"c:\source\scripts\part.txt"

echo create partition primary align=64>>"c:\source\scripts\part.txt"

echo assign letter=F >>"c:\source\scripts\part.txt"

echo active >>"c:\source\scripts\part.txt"

rem Create Partition

DiskPart /s "c:\source\scripts\part.txt"

rem Format Partition

format F: /FS:NTFS /V:fdrive /q /A:32K /y






Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.