19 Replies Latest reply: Oct 21, 2015 10:31 AM by Yuri Olinares RSS

    Automate ESX Datastore creation with Nimble PowerShell Module

    Justin Rich Adventurer

      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