Jump to content
Sign in to follow this  

Need help with writing a diskpart script "on the fly"

Recommended Posts

First of all, thank you for all the great help you guys provide in here. Im truly grateful

I have writte a XML file which contains information about a possible disk configuration and based on the information in that file, it will write a diskpart script.

I know how to get the information out from the XML file, but creating the diskpart.txt the proper way is more difficult, and so far i haven't been able to succeed

My XML file content looks like this:

    <disk setting="Full Disc">
        <name>Full Disc</name>
            <partition id="1">
                <settings type="size">
                <settings type="letter">
                <settings type="label">
            <partition id="2">
                <settings type="size">
                <settings type="letter">
                <settings type="label">

And my script looks like this:

local $xmlDoc, $xmlNode, $diskpart_path

$xmlDoc = ObjCreate("Microsoft.XMLDOM")
$xmlNode = $xmlDoc.documentElement.selectNodes("/diskconfigurations/disk[@setting='Full Disc']/partitions/partition/settings/size")
$xmlLetter = $xmlDoc.documentElement.selectNodes("/diskconfigurations/disk[@setting='Full Disc']/partitions/partition/settings/driveletter")
$xmlLabel = $xmlDoc.documentElement.selectNodes("/diskconfigurations/disk[@setting='Full Disc']/partitions/partition/settings/label")

$diskpart = "c:\users\doni\desktop\diskpart.txt"

filewrite($diskpart, "select disk 0" & @crlf _
                  &  "clean" & @crlf _
for $xmlNodes in $xmlNode

   filewrite($diskpart, "create partition primary size=" & $xmlNodes.text & @crlf)
   filewrite($diskpart, "assign letter=" & $xmlLetter.text & @crlf)
   filewrite($diskpart, "label=" & $xmlLabel.text & @crlf)


And the above so far outputs:

select disk 0
create partition primary size=100
assign letter=
create partition primary size=250
assign letter=

Im missing the letter and the labels, but using selectSingle node will place the same drive letter everytime


Any help is appreciated

Thanks in advance!

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...