stankes Posted December 30, 2004 Share Posted December 30, 2004 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? Link to comment Share on other sites More sharing options...
Halal-Al Posted January 20, 2005 Share Posted January 20, 2005 We (IT@LEGO Company) use a vbscript for that:Set WshShell = WScript.CreateObject("WScript.Shell")Set fso = CreateObject("Scripting.FileSystemObject")Dim disk, drivewscript.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, TRUESet 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 winsDISKMIN=5DISKUSE=50'Set disksize to minimum 5Gb, but use half the actual max disk size (50%)'or...DISKMIN=5DISKUSE=0'Set disksize to 5Gbwscript.echo "Setting the partition size of primary disk."Dim ValueDISKMIN, ValueDISKUSE, partsizeIf Not DISKMIN = "" Then wscript.echo "DISKMIN=" & diskmin & "GB" ValueDISKMIN = DISKMIN * 1024End IfIf (Not DISKUSE = "") and (Not DISKUSE = "(NONE)") Then wscript.echo "DISKUSE=" & diskuse ValueDISKUSE = Disk * (DISKUSE / 100) Else ValueDISKUSE = DiskEnd IfIf ValueDISKMIN > Disk then ValueDISKMIN = DiskIf ValueDISKMIN > ValueDISKUSE then partsize = ValueDISKMINelse partsize = ValueDISKUSEend ifpartsize = partsize - 5partsize = "Size=" & partsize'***************************' Modify DISKPART-File'***************************wscript.echo "Modifying DISKPART input file to " & partsizefso.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)Wendinput.Closeoutput.Closefso.DeleteFile sTXTSet input = NothingSet output = Nothing' ***********************' Partitioning disk 0 *' ***********************wscript.echo "Now partitioning primary disk."WshShell.Run "diskpart /s diskmain.txt", 7, TRUEWshShell.Run "format c: /fs:ntfs /v:System /q /y", 7, TRUEThe DelAndCreate.txt should look something like this:sel disk 0cleanCre par prisel par 1assign letter=cexitAnd the diskpart_template.txt like this:sel disk 0sel par 1del parCre par pri ##SIZEsel par 1assign letter=cexitThe 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 More sharing options...
Br4tt3 Posted January 20, 2005 Share Posted January 20, 2005 Go Lego boys... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now