MSFN Forum: How to use diskpart with /s - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to use diskpart with /s Rate Topic: -----

#1 User is offline   stankes 

  • Group: Members
  • Posts: 1
  • Joined: 30-December 04

  Posted 30 December 2004 - 01:46 PM

I am wanting to use diskpart /s to partition the harddrive via percentage of the drive. What is the easiest way to accomplish this task via the scripting option? ;)


#2 User is offline   Halal-Al 

  • Group: Members
  • Posts: 7
  • Joined: 20-January 05

Posted 20 January 2005 - 02:38 AM

We (IT@LEGO Company) use a vbscript for that:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

Dim disk, drive

wscript.echo "Deleting primary disk"
WshShell.Run "diskpart /s DelAndCreate.txt", 7, TRUE  'Delete all partitions, create one primary, assign letter C:
WshShell.Run "format c: /fs:ntfs /v:temp /q /y", 7, TRUE

Set Drive = fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName("C:\")))
Disk = FormatNumber(Drive.TotalSize /1048576, 0,0,0,0)
'Now we know the max size of the disk.

'DISKMIN is the minimum size in GB
'DISKUSE is the minimum procentage of the disk to use
'The highest of the two wins

DISKMIN=5
DISKUSE=50
'Set disksize to minimum 5Gb, but use half the actual max disk size (50%)
'or...

DISKMIN=5
DISKUSE=0
'Set disksize to 5Gb

wscript.echo "Setting the partition size of primary disk."
Dim ValueDISKMIN, ValueDISKUSE, partsize
If Not DISKMIN = "" Then
    wscript.echo "DISKMIN=" & diskmin & "GB"
    ValueDISKMIN = DISKMIN * 1024
End If
If (Not DISKUSE = "") and (Not DISKUSE = "(NONE)") Then
    wscript.echo "DISKUSE=" & diskuse
	ValueDISKUSE = Disk * (DISKUSE / 100)  
Else
    ValueDISKUSE = Disk
End If
If ValueDISKMIN > Disk then ValueDISKMIN = Disk
If ValueDISKMIN > ValueDISKUSE then
	partsize = ValueDISKMIN
else
	partsize = ValueDISKUSE
end if
partsize = partsize - 5
partsize = "Size=" & partsize

'***************************
' Modify DISKPART-File
'***************************
wscript.echo "Modifying DISKPART input file to " & partsize
fso.copyfile "diskpart_template.txt", "disktmp.txt"
sTMP = "Diskmain.txt"
sTXT = "disktmp.txt"
Set input = fso.OpenTextFile(sTXT, 1)
Set output = fso.CreateTextFile(sTMP, True)
While Not input.AtEndOfStream
	sOneLine = input.ReadLine
	sOneLine = Replace(sOneLine, "##SIZE", partsize)
	output.WriteLine(sOneLine)
Wend
input.Close
output.Close
fso.DeleteFile sTXT
Set input = Nothing
Set output = Nothing

' ***********************
' Partitioning disk 0 *
' ***********************
wscript.echo "Now partitioning primary disk."
WshShell.Run "diskpart /s diskmain.txt", 7, TRUE
WshShell.Run "format c: /fs:ntfs /v:System /q /y", 7, TRUE


The DelAndCreate.txt should look something like this:

sel disk 0
clean
Cre par pri
sel par 1
assign letter=c
exit

And the diskpart_template.txt like this:
sel disk 0
sel par 1
del par
Cre par pri ##SIZE
sel par 1
assign letter=c
exit


The above code is a cutout of the scripts we use, and not tested alone, but I hope you can use this.

#3 User is offline   Br4tt3 

  • World famous sausage eater...
  • PipPipPipPip
  • Group: Members
  • Posts: 566
  • Joined: 20-April 04

Posted 20 January 2005 - 03:23 AM

Go Lego boys... ;)

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy