Mass creation of new datastores with fibre channel storage backend 0

I was recently tasked with adding 16 datastores to a new vSphere 5.5 cluster.  In this environment, we use EMC VMAX fibre channel storage on the backend.

I wanted to post this example PowerCLI code in hopes someone else might find it useful.  I have previously found other examples online, however, they were geared towards iSCSI and NFS storage instead of fibre channel.  The SCSI device canonical name is very different for fibre channel compared to the other storage protocols.

Enjoy!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# NOTE: In our environment, we begin our actual datastore LUN #'s at 2. As such
# you may need to adjust the logic below as necessary.
 
# Configuration:
$MyHost = "dc4compute02-esxi001.dc4.mydomain"
$DatastorePrefix = "dc4compute02-storage"
# End Config
 
$ESXiHost = Get-VMHost $MyHost
$ESXiHost | Get-VMHostStorage -RescanAllHba
 
1..16 | ForEach-Object {
	$DatastoreName = "{0:D3}" -f $_
	$LUNNum = $_ + 1
 
	Write-Host "DS Name:  $DatastorePrefix$DatastoreName     -     LUN: $LUNNum"
 
	$LUN = $ESXiHost | Get-ScsiLun | Select RuntimeName,CanonicalName | Where { $_.RuntimeName -eq "vmhba1:C0:T0:L$LUNNum" }
	$ESXiHost | New-Datastore -Vmfs -Name "$DatastorePrefix$DatastoreName" -Path $LUN.CanonicalName -FileSystemVersion 5
}