Array Setup and Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

Automate ESX Datastore creation with Nimble PowerShell Module

 
Highlighted
Trusted Contributor

Automate ESX Datastore creation with Nimble PowerShell Module

Here is a quick script that will add an additional volume to your ESX environment.

It requires the Nimble PowerShell Module and PowerCLI

#Connect to VCenter and Nimble Array

Connect-VIServer -Server $vcenter

Connect-NSArray -SystemName $ip -Password $password

#define settings

$vmhost = get-vmhost $VMHostName

$volumeName = "Nimble04"

$InitGroupName = "ESX"

$Size = 2tb

# Create a new volume

$vol = New-NSVolume -Name $volumeName -Size $Size -MultipleInitiator -PerformancePolicy 'VMware ESX 5'

# Provide the ESX hosts access to that volume

Add-NSInitiatorGroupToVolume -InitiatorGroup $InitGroupName -Volume $volumeName -Access Both

# Find the volume on the ESX host

$target = $vol.serialnumber

Get-VMHost -Server $nvm | Get-VMHostStorage -RescanAllHba

$lun = Get-ScsiLun -VmHost $vmhost -CanonicalName "eui.$target"

$canonicalName = $lun.canonicalname

# Create the new DataStore

New-Datastore -Name $volumeName -Path $canonicalName -Vmfs -VMHost $vmhost

Get-VMHost | Get-VMHostStorage -RescanAllHba

# Make sure the Multipathing is setup correctly (RoundRobin)

get-vmhost | Get-ScsiLun -CanonicalName $canonicalName | ?{$_.multipathpolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin

19 REPLIES 19
Highlighted
Frequent Advisor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

Any reason why you're confirming the use of Round Robin for multipathing rather than using the Nimble Path Selection Plugin?

Nimble 2.0 PSP Integration with VMware vSphere Part I (VIB Install) | super sonic dog (S.S.D)

Nimble 2.0 PSP Integration with VMware vSphere Part II (NCS + PSP deep dive) | super sonic dog (S.S.D)

Should be out on Infosight also.Todd Moore

Highlighted
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

I dont believe 2.0 is technically released yet, also I havent seen it before, looks pretty neat though.

Highlighted
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

Julian, one reason to still use the native RoundRobin is due to VMware licensing. To use a third-party PSP requires Enterprise or Enterprise Plus licensing.

Highlighted
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

Hi Justin,

             I've tried your script and everything work fine except for the the Performance policy. It appears that if the performance policy has spaces in it's name it will not read/apply regardless of whether it's in single of double quotes .... or indeed without.

In addition the embedded "VMware ESX 5" policy has spaces in it's name as do other standard policies but you cannot create a new performance policy through the Nimble Web interface with any spaces in the name .... as designed. Our array is a 460G on version 1.4.9..

If I use the default policy or create a new policy with no spaces it's fine.

Here's the error

"

New-NSVolume : Cannot validate argument on parameter 'PerformancePolicy'. The argument "VMware ESX 5" does not belong to

the set "default,ESX-5,'Exchange 2003 data store','Exchange 2007 data store','Exchange 2010 data store','Exchange

log',George-5,'Hyper-V CSV','Oracle OLTP',SharePoint,'SQL Server','SQL Server 2012','SQL Server Logs','VMware

ESX','VMware ESX 5','VMware VDI','Windows File Server'" specified by the ValidateSet attribute. Supply an argument that

is in the set and then try the command again.

At C:\NimblePowerShell-master\createDatastoreandVolume.ps1:13 char:89

+ ... formancePolicy $pp

+                    ~~~

    + CategoryInfo          : InvalidData: (:) [New-NSVolume], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,New-NSVolume

Add-NSInitiatorGroupToVolume : Error adding  to the list! code: SMeinval

At C:\NimblePowerShell-master\createDatastoreandVolume.ps1:15 char:1

+ Add-NSInitiatorGroupToVolume -InitiatorGroup $InitGroupName -Volume $volumeName  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-NSInitiatorGroupToVolume"

Highlighted
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

hmm, so if you add the quotes it still gives the same error?

I had run in to the problem myself with the spaces but adding the quotes did it for me.

Im trying to dig in to it a bit more but from what i can tell its a bug in how tab expansion works. Im usind "dynamic parameter" which reads in the possibilities and makes that the validation set. I tried adding quotes as it read them in, but then it shows the quotes in the ISE intellisense.

However it really should accept it if you put it in quotes.

can you show me the line as you typed it?

Highlighted
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

#Import the PowerCLI module
Add-PSSnapin VMware.VimAutomation.Core
$ip = "10.7.1.1"
$vcenter = "10.7.3.200"
$password = "NOWAYJose"
Connect-VIServer -Server $vcenter
Connect-NSArray -SystemName $ip -Password $password
$vmhost = get-vmhost Esxi-01.smbc.loc
$volumeName = "Nimble-123"
$InitGroupName = "ESXi-SMBC-CLUSTER-1"
$Size = 125gb
$pp = "default"

# Create a new volume
$vol = New-NSVolume -Name $volumeName -Size $Size -MultipleInitiator -PerformancePolicy $pp
# Provide the ESX hosts access to that volume
Add-NSInitiatorGroupToVolume -InitiatorGroup $InitGroupName -Volume $volumeName -Access Both
# Find the volume on the ESX host
$target = $vol.serialnumber

Get-VMHost -Server $nvm | Get-VMHostStorage -RescanAllHba
$lun = Get-ScsiLun -VmHost $vmhost -CanonicalName "eui.$target"
$canonicalName = $lun.canonicalname

# Create the new DataStore
New-Datastore -Name $volumeName -Path $canonicalName -Vmfs -VMHost $vmhost
Get-VMHost | Get-VMHostStorage -RescanAllHba

# Make sure the Multipathing is setup correctly (RoundRobin)
get-vmhost | Get-ScsiLun -CanonicalName $canonicalName | ?{$_.multipathpolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin

Highlighted
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

instead of $pp = "default" it said $pp = "VMware ESX 5"  I tried 'VMware ESX 5' and "'VMware ESX '5"

The previous script with "Default" ran OK.

Cheers,

            Mark.

Highlighted
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

you know, im not sure i tried it with it being assigned to a variable, I always just typed it in on the new-snvolume line.

I'll play around with it that way and see what i come up with.

Highlighted
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

With or without the variable the outcome is the same.