Configure disks using PowerShell in Windows 2012 R2

When installing and configuring a large Exchange environment you most likely will have a lot of disks attached to the Exchange servers. Manual configuration of the disks is no fun so PowerShell is your friend here.

These are the steps that need to be done:

  • Create directory structure for the Mount Points (New-Item).
  • Set the disks online and initialize them (Initialize-Disk).
  • Create the partitions (New-Partition).
  • Link them into the Mount Point structure (Add-PartitionAccessPath)
  • Format them (Format-Volume).

Please make sure the that Execution Policy on your server is set to Unrestricted:

 Set-ExecutionPolicy –Unrestricted

I am working on a large Exchange deployment with 28 Mailbox servers where all Mailbox servers are equipped with 48 disks, each 2TB in size.To configure this amount of storage I used the following commands:

To create the Directory structure for the Mount Points:

 For ($i=1; $i -le 49; $i++) {New-Item C:\ExDb\MDB$i –ItemType Directory}

To configure and format the individual disks you can just save the following in a .ps1 file and run it.

 For ($i=2; $i -le 49; $i++) {
Get-Disk –Number $i | Initialize-Disk –PartitionStyle GPT}
$MDBCounter = $i-1
$MDB = "MDB$MDBCounter"
New-Partition –DiskNumber $i –UseMaximumSize
Add-PartitionAccessPath -DiskNumber $i -PartitionNumber 2 –AccessPath "C:\ExDb\$MDB"
Get-Partition –Disknumber $i –PartitionNumber 2 | Format-Volume –FileSystem NTFS –NewFileSystemLabel $MDB -AllocationUnitSize 65536 –Confirm:$false

After running this I have 48 formatted disk on my Exchange server, ready for use.

Update.  Added the -AllocationUnitSize option on the Format-Volume cmdlet. More information can be found on the Microsoft TechNet Exchange 2013 Storage Configuration Options document.

4 thoughts on “Configure disks using PowerShell in Windows 2012 R2”

  1. thank you that was helpful,
    my builds are same so there was no need for automation so I did a static script:
    ———mount point SQL———–
    Get-Disk –Number 1 | Initialize-Disk -PartitionStyle MBR -PassThru
    New-Partition -DiskNumber 1 -AssignDriveLetter -UseMaximumSize
    Get-Partition –Disknumber 1 | Format-Volume -FileSystem NTFS -NewFileSystemLabel “disk2” -Confirm:$false
    Get-Disk –Number 2 | Initialize-Disk –PartitionStyle GPT
    New-Partition –DiskNumber 2 –UseMaximumSize
    New-Item -ItemType directory -Path D:\SQL1\DB
    Add-PartitionAccessPath -DiskNumber 2 -PartitionNumber 2 –AccessPath “D:\SQL1\DB”
    Get-Partition –Disknumber 2 –PartitionNumber 2 | Format-Volume –FileSystem NTFS –NewFileSystemLabel DB -AllocationUnitSize 65536 –Confirm:$false

    VMware adds always same disk numbers so numbering is static.

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s