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

Automate ESX Datastore creation with Nimble PowerShell Module

jrich52352
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
julez66
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

jrich52352
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.

aherbert23
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.

marktheblue45
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"

jrich52352
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?

marktheblue45
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

marktheblue45
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.

jrich52352
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.

marktheblue45
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

With or without the variable the outcome is the same.

jrich52352
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

hmm so i just ran this line

New-NSVolume  -Name "test" -Size 2tb -MultipleInitiator -PerformancePolicy 'VMware ESX 5'

and it ran successfully. when did you install the module? it could possibly be an older release that had a bug in it?

marktheblue45
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

Same line that failed for me. Have you got a pointer for the modules you used.

marktheblue45
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

As per your link Justin

jrich52352
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

just to be safe, close powershell, delete the Nimble folder in the modules folder (my documents\windowspowershell\modules)

then open up powershell and run this

ex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/jrich523/NimblePowerShell/master/Install.ps1')


also, what version of powershell are you using? nothing comes to mind as to why this wouldnt work in V2, but this is designed around V3

jrich52352
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

fixed the problem, you'll have to install it again (couple of code changes). you still need to manually supply the quotes, but at least now it works!

marktheblue45
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

I'll give it a go tomorrow. I'm using PowerShell v3 and esxi 5.5

jrich52352
Trusted Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

im actually making a few other modifications right now, so you'll want to download it again tomorrow.

marktheblue45
Valued Contributor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

Worked a treat. Thanks. Need to learn Powershell basics and some to fully understand some of the snippets on here.

brichardson15
Occasional Advisor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

I've tried running that same exact command and I'm receiving an error...

New-NSVolume : Error Creating volume test! code: SMeinval

At line:1 char:1

+ New-NSVolume  -Name "test" -Size 2tb -MultipleInitiator -PerformancePolicy 'VMwa ...

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

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

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-NSVolume

I'm running PS version 3.0 and I'm running version 1.1.20140407.1024 of the Nimble module.

yolinares27
Occasional Visitor

Re: Automate ESX Datastore creation with Nimble PowerShell Module

I am running the latest powershell module from GitHub, running powershell 4.0 and my nimbles are running 2.2.9.0-269169-opt. This is the command im running and the error im getting:

New-NSVolume -PerformancePolicy default -Name "test" -Description "test" -Size 500GB -MultipleInitiator

New-NSVolume : Error Creating volume test! code: SMeinval

At line:1 char:1

+ New-NSVolume -PerformancePolicy default -Name "test" -Description "test" -Size 5 ...

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

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

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-NSVolume

New-NSVolume -PerformancePolicy "VMware ESX 5" -Name "test" -Description "test" -Size 500GB -MultipleInitiator

New-NSVolume : Error Creating volume test! code: SMeinval

At line:1 char:1

+ New-NSVolume -PerformancePolicy "VMware ESX 5" -Name "test" -Description "test"  ...

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

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

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-NSVolume