3

I'm trying to write a script to create and format a partition in Windows Server 2008R2.

Now, when disk 1 is selected, I need to format it, only if it is not formatted already. This is what I have now:

Run: diskpart /s script.txt

Content of script.txt

select disk 1
clean
create partition primary
format fs=ntfs unit=65536 quick
active
assign letter=D

Any help?

ccamacho
  • 213

2 Answers2

2

This works for me.

foreach ($disk in get-wmiobject Win32_DiskDrive -Filter "Partitions = 0"){ 
   $disk.DeviceID
   $disk.Index
   "select disk "+$disk.Index+"`r clean`r create partition primary`r format fs=ntfs unit=65536 quick`r active`r assign letter=D" | diskpart
}

In this case, i get the disk with NO partitions, and then i create a D drive with all available space

ccamacho
  • 213
0

I did this a while back using here strings to format the complete diskpart commands. It's a bit goofy looking but it worked at the time when we were trying to automate this quickly for a high number of luns on multi node clusters. the WMI method is definitely cleaner looking.

Gags
  • 31