Jump to content

How to use diskpart with /s


stankes

Recommended Posts

  • 3 weeks later...

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.

Link to comment
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.
×
×
  • Create New...