VMware PowerCLI – Adding VMFS Datastore’s

Thank you Cliff, Steve and Luc for helping me out with this task.

After you have created the required LUN’s on your storage array and mapped the LUN’s to your ESXi hosts, at this stage you may use PowerCLI to add these new LUNs as VMFS datastore’s.

1. Connect to vCenter:
Connect-VIServer -Server “vcenter_IP” -User UserName -Password Password

If you need to retreive the Cluster and Host names:
look up the Cluster Name:
Get-Cluster
look up the Host names in the cluster:
Get-Cluster ‘Cluster Name’ | Get-VMHost | Select Name

2. Retrieve the Canonical Name(s):
In order to use the New-Datastore cmdlet we require the ‘Canonical Name’ parameter associated with each LUN. In this example we will use the Get-SCSILun cmd to return the ‘Canonical Name’, Capacity and Runtime name in order for us to match the unique naa with the correct LUN#.

Get-SCSILun -VMhost “YourESXiHostname” -LunType Disk | Select CanonicalName,CapacityGB,runtimename

Runtime

The naa’s and runtime names are returned, but we want to order the output by the runtime names ‘LUN ID’ ‘vmhba1:C0:T0:L#’. Uning the | sort-object runtimename parameter the LUNs are ordered, but the double digit’s are not recognised:

sort-object

I was able to sort the SCSI LUN’s by RuntimeName including the double digit’s ‘vmhba1:C0:T0:L##’ using the following script provided by Luc:

Get-ScsiLun -VMHost “YourESXiHostname” -LunType disk |
Select RuntimeName,CanonicalName,CapacityGB |
Sort-Object -Property {$_.RuntimeName.Split(‘:’)[0],
[int]($_.RuntimeName.Split(‘:’)[1].TrimStart(‘C’))},
{[int]($_.RuntimeName.Split(‘:’)[2].TrimStart(‘T’))},
{[int]($_.RuntimeName.Split(‘:’)[3].TrimStart(‘L’))}

sort-object1

3. Adding the New VMFS Datatore’s:
vSphere PowerCLI provides the New-Datastore cmd to create the VMFS Datastore(s):

New-Datastore -VMHost “YourESXiHostname” -Name ‘VMFS_Datastore_1’ -Path naa.60000xxxxxxxxxxxxxxxxx36 -vmfs
New-Datastore -VMHost “YourESXiHostname” -Name ‘VMFS_Datastore_2’ -Path naa.60000xxxxxxxxxxxxxxxxx42 -vmfs

4. Rescanning the Cluster for the New VMFS Datastores:
To rescan the entire cluster of ESXi host’s for the VMFS volumes added, issue the following PowerCLI cmd to rescan all the ESXi hosts HBA’s:

Get-Cluster -name “YourClusterName” | Get-VMhost | Get-VMHostStorage –RescanAllHBA

5. List all the Newly Created VMFS Datastore’s:
Get-Datastore -VMhost “YourESXiHostname”
Get-Cluster -name “ClusterName” | Get-VMhost | Get-Datastore

******************************************************************************************

Script to Automate Adding VMFS Volumes
Here is a script which Steve Keating kindly helped put together which scans for the Host LUN ID and then attributes the $LUN_ parameter to the ‘Canonical Name’. This greatly simplifies the process of adding large quantities of VMFS datastore’s.

For example if we know the following:
Host LUN ID ‘1’ will equal ‘VMFS_Datastore_1’
Host LUN ID ‘2’ will equal ‘VMFS_Datastore_2’
etc…
The following example script will automatically create four VMFS datastore’s and scan the Hosts HBA’s:

###VMFS_Datastore_1###
$LUN_1 = Get-SCSILun -VMhost YourESXiHostname -LunType Disk | Where-Object {$_.runtimename -like "*L1"} | Select CanonicalName,runtimename
$LUN_1 = $LUN_1 | Select CanonicalName
$LUN_1 = $LUN_1 -replace "@{CanonicalName=", ""
$LUN_1 = $LUN_1 -replace "}", ""
$LUN_1
New-Datastore -VMHost YourESXiHostname -Name VMFS_Datastore_1 -Path $LUN_1 -Vmfs

###VMFS_Datastore_2###
$LUN_2 = Get-SCSILun -VMhost YourESXiHostname -LunType Disk | Where-Object {$_.runtimename -like "*L2"} | Select CanonicalName,runtimename
$LUN_2 = $LUN_2 | Select CanonicalName
$LUN_2 = $LUN_2 -replace "@{CanonicalName=", ""
$LUN_2 = $LUN_2 -replace "}", ""
$LUN_2
New-Datastore -VMHost YourESXiHostname -Name VMFS_Datastore_2 -Path $LUN_2 -Vmfs

###VMFS_Datastore_3###
$LUN_3 = Get-SCSILun -VMhost YourESXiHostname -LunType Disk | Where-Object {$_.runtimename -like "*L3"} | Select CanonicalName,runtimename
$LUN_3 = $LUN_3 | Select CanonicalName
$LUN_3 = $LUN_3 -replace "@{CanonicalName=", ""
$LUN_3 = $LUN_3 -replace "}", ""
$LUN_3
New-Datastore -VMHost YourESXiHostname -Name VMFS_Datastore_3 -Path $LUN_3 -Vmfs

###VMFS_Datastore_4###
$LUN_4 = Get-SCSILun -VMhost YourESXiHostname -LunType Disk | Where-Object {$_.runtimename -like "*L4"} | Select CanonicalName,runtimename
$LUN_4 = $LUN_4 | Select CanonicalName
$LUN_4 = $LUN_4 -replace "@{CanonicalName=", ""
$LUN_4 = $LUN_4 -replace "}", ""
$LUN_4
New-Datastore -VMHost YourESXiHostname -Name VMFS_Datastore_4 -Path $LUN_4 -Vmfs

###Scan Cluster Hosts HBA’s###
Get-Cluster -name "YourClusterName" | Get-VMhost | Get-VMHostStorage –RescanAllHBA

Cisco MDS – Clear All Zoning Configuration

The steps below detail the process of clearing all zoning configurations on an MDS switch. Including: fcaliases, zonesets and zones. If you wish to remove individual zones from a zoneset then please see post here: How To Remove Zones from an Active Zoneset

Note: Ensure this is a standalone switch; if it is connected to other switches in the fabric then you may potentially affect the entire fabric.

1. Firstly determine the names of the active zonesets for each vsan. In this example we will clear down all the zoning associated with the zonset “vsan10_zs” on vsan 10:

MDS-9148# show zoneset active | inc zoneset
zoneset name vsan10_zs vsan 10

2. Next you will need to deactivate the zoneset “vsan10_zs” on vsan 10:

MDS-9148# conf t
MDS-9148(config)# no zoneset activate name vsan10_zs vsan 10
Enhanced zone session has been created. Please ‘commit’ the changes when done.
MDS-9148(config)# zone commit vsan 10
Commit operation initiated. Check zone status

3. Remove the zonset “vsan10_zs” from the configuration:

MDS-9148(config)# no zoneset name vsan10_zs vsan 10
MDS-9148(config)# zone commit vsan 10
MDS-9148(config)# show zoneset active
Zoneset not present

4. Clear all the zones from the database associated with vsan 10:

MDS-9148# clear zone database vsan 10
Enhanced zone session has been created. Please ‘commit’ the changes when done.
MDS-9148(config)# zone commit vsan 10
MDS-9148(config)# show zone
Zone not present
MDS-9148# show fcalias
Alias not present

5. Clear any device alias entries:
MDS-9148(config)# clear device-alias database
MDS-9148(config)# device-alias commit
MDS-9148(config)# show device-alias database

6. Exit config mode, save your running config to startup and reload the switch:

MDS-9148(config)# exit
MDS-9148# copy run startup-config
[########################################] 100%
Copy complete, now saving to disk (please wait)…
MDS-9148# reload
This command will reboot the system. (y/n)? [n] y

Then apply your new zoning configuration:
copy ftp://FTP-Server-IP/Zoning.cfg system:running-config

EXAMPLE

#### FABRIC A ####
show zoneset active | inc zoneset

conf t
no zoneset activate name vsan10_zs vsan 10
zone commit vsan 10

no zoneset name vsan10_zs vsan 10
zone commit vsan 10
show zoneset active

clear zone database vsan 10
zone commit vsan 10
show zone
show fcalias

clear device-alias database
device-alias commit
show device-alias database

exit
copy run startup-config

#### FABRIC B ####
show zoneset active | inc zoneset

conf t
no zoneset activate name vsan11_zs vsan 11
zone commit vsan 11

no zoneset name vsan10_zs vsan 11
zone commit vsan 11
show zoneset active

clear zone database vsan 11
zone commit vsan 11
show zone
show fcalias

clear device-alias database
device-alias commit
show device-alias database

exit
copy run startup-config

## Then apply your new zoning configuration: ##
copy ftp://10.10.10.1/ZoningA.cfg system:running-config
show zoneset active
copy run start
copy ftp://10.10.10.1/ZoningB.cfg system:running-config
show zoneset active
copy run start

If prompted for ‘vrf’ the default entry is ‘management’:
Enter vrf (If no input, current vrf ‘default’ is considered): management