Compellent PowerShell Command Set

At the end of 2008/beginning of 2009, Compellent announced the release of the Compellent Command Set, which is a full-featured PowerShell snap-in to manage a Compellent SAN, as well as many tasks in Windows around the area of Disk Management. For those lucky IT administrators that have a Compellent SAN, gone are the days of having to figure out clever ways of scripting diskpart by saving out text files to Windows hosts and executing those files through psexec or some remote shell. Compellent’s snap-in provides an end-to-end tool creating LUNs, mapping them to your servers, and setting up the corresponding volumes from inside Windows. Here’s an example script to show you how easy it is to create a new LUN and bring up a new volume in Windows. To help visualize how short this script is, I’m going to paste it twice – once without comments, and once with comments. In PowerShell, code is generally so concise that the number of lines of containing comments and documentation generally outnumbers the lines of code by quite the margin.

function Create-NewWindowsVolumeFromSAN ($lunname = $(throw "LUN name required"))
{process
{
if (Get-PSSnapin -Name Compellent.StorageCenter.Scripting 2>$null) {}
else    {Add-PSSnapin -Name Compellent.StorageCenter.Scripting}
$volume = New-SCVolume -Name $lunname -Size 500g -ParentFolder MYFOLDER
sleep 3
New-SCVolumeMap -VolumeIndex $volume.Index -ServerName MYSERVER
$i=0
While(!(get-diskdevice -Server MYSERVER -SerialNumber $volume.SerialNumber) –and ($i -lt 10))
{Rescan-DiskDevice -Server MYSERVER -RescanDelay 5;$i++}
if($i -eq 10){Throw "Unable to find disk device on server!";Break}
Set-DiskDevice -Server MYSERVER -SerialNumber $volume.SerialNumber -readonly:$false
$disk = Set-DiskDevice -Server MYSERVER -SerialNumber $volume.SerialNumber -Online
$nvol = New-Volume -server MYSERVER -DeviceName $disk.DeviceName -label $lunname
}
}
function Create-NewWindowsVolumeFromSAN ($lunname = $(throw "LUN name required"))
{
#.Synopsis
#
# Creates a LUN on the Compellent SAN and maps it up to the server, which is hardcoded in this script
#.Description
#
#.Example
#
# Create-NewWindowsVolumeFromSAN MYTEST01
Process
{
#### Add the Compellent snap-in if it's not already added
if (Get-PSSnapin -Name Compellent.StorageCenter. Scripting 2>$null) {}
else    {Add-PSSnapin -Name Compellent.StorageCenter.Scripting}
### Create a new 500GB LUN in the folder called MYFOLDER
### Change Parent to meet your needs, or parameterize it in the function
$volume = New-SCVolume -Name $lunname -Size 500g -ParentFolder MYFOLDER
### Sleep a few seconds to let the LUN finish creating
sleep 3
### Map the volume to your server on the server called MYSERVER
### This name is the name of the server as displayed by your Compellent UI,
### and not necessarily the NetBIOS name of the server,
### though you should make these the same as a best practice
### Change Server name to meet your needs, or parameterize it in the function
New-SCVolumeMap -VolumeIndex $volume.Index -ServerName MYSERVER
### Create a "Rescan Disk loop in order to keep looking for the volume until it shows up in Windows
### The server name listed below is the actual NetBIOS name of the server to which you wish to map your LUN
### Change Server name to meet your needs, or parameterize it in the function
$i=0
While(!(get-diskdevice -Server MYSERVER -SerialNumber $volume.SerialNumber) –and ($i -lt 10))
{Rescan-DiskDevice -Server MYSERVER -RescanDelay 5;$i++}
if($i -eq 10){Throw "Unable to find disk device on server!";Break}
### Set the "Read-only" bit to false. This is required when scripting the online of a disk rather than using Disk Management GUI
Set-DiskDevice -Server MYSERVER -SerialNumber $volume.SerialNumber -readonly:$false
### Bring the disk online. In Windows 2008 and above, all SAN disks are always first presented to Windows in Offline mode.
$disk = Set-DiskDevice -Server MYSERVER -SerialNumber $volume.SerialNumber -Online
### Initialize the disk and format the volume, giving it a volume label to match your LUN name.
$nvol = New-Volume -server MYSERVER -DeviceName $disk.DeviceName -label $lunname
}
}

For more information on scripting with the Compellent PowerShell Command Set, check out the user group at http://compellentpowershell.groups.live.com. Happy scripting!

Janssen

Change is in the air

A lot of time has passed since my last post, and wow – things have changed! Ushering in the era of change with the candidate of change, the world as I knew it in 2008 has changed dramatically in 2009. On a personal note, my wife and I had our first baby (a 5lb 9 oz baby boy) in March. Talk about a change in routine! Also, I received the Microsoft MVP award for Virtualization, due to work with System Center Virtual Machine Manager. You’ll be seeing a lot of posts in the coming days about what’s coming soon in VMM R2 – But on to the matters I have generally blogged about:

Nearly every technology item I’ve posted on in the past year has changed dramatically. A few examples:

  • Scripting against a Compellent SAN (with the introduction of the Compellent PowerShell Command Set)
  • Scripting Failover Clustering (with the introduction of the Win2K8 R2 RC and its corresponding + PowerShell Failover Cluster cmdlets)
  • Scripting Windows Disk Management (with Compellent’s new Command Set for Windows Disk Management)
  • Scripting the creation of virtual machines from SAN replays using System Center Virtual Machine Manager R2 (which is on the verge of releasing a Release Candidate in the coming weeks)

The release of the aforementioned technologies has rendered virtually every one of my previous blog posts obsolete. However, the good news is that I’ll be posting a series of updated scripts demonstrating how much easier it is to script the creation of a clustered virtual environment in 2009. Stay tuned!