Sign in to follow this  
Followers 0
doestergaard

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

1 post in this topic

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:

<diskconfigurations>
    <disk setting="Full Disc">
        <name>Full Disc</name>
        <path>c:\users\doni\desktop\xml\diskconfig0.txt</path>
        <partitions>
            <partition id="1">
                <settings type="size">
                    <size>100</size>
                </settings>
                <settings type="letter">
                    <driveletter>S</driveletter>
                </settings>
                <settings type="label">
                    <label>System</label>
                </settings>
            </partition>
            <partition id="2">
                <settings type="size">
                    <size>250</size>
                </settings>
                <settings type="letter">
                    <driveletter>C</driveletter>
                </settings>
                <settings type="label">
                    <label>OS</label>
                </settings>
            </partition>
        </partitions>
    </disk>
</diskconfigurations>

And my script looks like this:

local $xmlDoc, $xmlNode, $diskpart_path

$xmlDoc = ObjCreate("Microsoft.XMLDOM")
$xmlDoc.load("c:\users\doni\desktop\xml\diskconfig.xml")
$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)

next

And the above so far outputs:

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

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  
Followers 0