Configuring 193 disks in under 2 minutes with PowerShell and diskpart.

Today at work I had to partition, format, and label, 193 disks, in Server 2008 R2. Each disk was a LUN on an EMC SAN. The server is an HP ProLiant BL460c G7 Server Blade. This will be an Exchange 2010 mailbox server that is part of a Database Availability Group (DAG) when it is finished, so 94 of these disks are for databases and 94 are for transaction logs.

5 of the disks received drive letters, the remaining 188 are to be volume mount points. There was no way I was going to do any of this manually, so I created some PowerShell scripts that use the diskpart command to do all the work for me. The result is having 5 disks partitioned, formatted, labeled and drive letters assigned. Then 188 folders get created for use as the volume mount points. The remaining 188 disks get partitioned, formatted, and labeled. I’m still trying to work out a way to script mapping the volume mount points to the folders, so this is a work in progress. (UPDATED: Click here to see how I solved this problem.)

First we have the primarydrives.txt script for diskpart to create the main drives that actually have letters assigned to them:

select disk 3
create partition primary NOERR
format FS=NTFS LABEL="SAN Exchange" UNIT=64K QUICK NOWAIT NOERR
assign letter=D NOERR
select disk 4
create partition primary NOERR
format FS=NTFS LABEL="SAN Temp" UNIT=64K QUICK NOWAIT NOERR
assign letter=T NOERR
select disk 196
create partition primary NOERR
format FS=NTFS LABEL="SAN Tracking Logs" UNIT=64K QUICK NOWAIT NOERR
assign letter=M NOERR
select disk 5
create partition primary NOERR
format FS=NTFS LABEL="SAN Databases" UNIT=64K QUICK NOWAIT NOERR
assign letter=E NOERR
select disk 6
create partition primary NOERR
format FS=NTFS LABEL="SAN Exchange" UNIT=64K QUICK NOWAIT NOERR
assign letter=L NOERR

Next we have the fvmpcreate.ps1 script that creates folders based on names in a text file. I had a spreadsheet with what the database names are going to be, so I just copied those to the text file to use for this script. This script also writes a text file for use by diskpart to partition, format, and label each disk. Like I said, I’m still working on how to get it to map the volume mount points to the folders created by the script.

# Folder and Volume Mount Point Creation Script
# By Josh M. Bryant
# www.fixtheexchange.com
# Last Updated 9/2/2011 3:40 PM
#
$dbfile = "C:Scriptsdbdrives.txt"
$logfile = "C:Scriptslogdrives.txt"
$dbdata = Get-Content C:Scriptsdbnames.txt
$ldata = Get-Content C:Scriptslognames.txt
$dbpath = "E:EXCH10"
$logpath = "L:EXCH10"
$drive = 6
#
#Create Database Folders and Volume Mount Points
#
ForEach ($line in $dbdata)
{$drive = $drive + 1
New-Item $dbpath$line -type directory
add-content -path $dbfile -value "select disk $drive"
add-content -path $dbfile -value "create partition primary NOERR"
add-content -path $dbfile -value "format FS=NTFS LABEL=`"$line`" UNIT=64K QUICK NOWAIT NOERR"
}
#
#Create Log Folders and Volume Mount Points
#
ForEach ($line in $ldata)
{$drive = $drive + 1
New-Item $logpath$line -type directory
add-content -path $logfile -value "select disk $drive"
add-content -path $logfile -value "create partition primary NOERR"
add-content -path $logfile -value "format FS=NTFS LABEL=`"$line`" UNIT=64K QUICK NOWAIT NOERR"
}

The last script I called createdrives.ps1, this is the master script that calls all the others.

# Exchange Drive Creation Script
# By Josh M. Bryant
# www.fixtheexchange.com
# Last Updated 9/2/2011 3:55 PM
#
# Create primary drives.
diskpart /s C:Scriptsprimarydrives.txt > primarydrives.log
# Wait for disks to format.
sleep 30
# Create EXCH10 Folders
New-Item E:EXCH10 -type directory
New-Item L:EXCH10 -type directory
# Create Folders and Diskpart Scripts
& "C:Scriptsfvmpcreate.ps1"
# Create Volume Mount Points for Databases
diskpart /s C:Scriptsdbdrives.txt > dbdrives.log
# Create Volume Mount Points for Logs
diskpart /s C:Scriptslogdrives.txt > logdrives.log

This ended up being a huge time saver. Everything completed in about 2 minutes. Even if I can’t figure out how to script out the volume mount point mapping, it will have saved me a tremendous amount of time. The best part is this is scalable, so I can easily adapt it for use on other servers, regardless of the number of disks that need to be configured.

UPDATE: Click here to see how I solved the volume mount point creation.

If you use these scripts, or want to re-post them anywhere else, please keep the author information at the top of the script, and include a link back to this site. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *