Skip to content

Instantly share code, notes, and snippets.

@Dapacruz
Created May 30, 2018 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dapacruz/151f0db2925fa54b09effee23338a770 to your computer and use it in GitHub Desktop.
Save Dapacruz/151f0db2925fa54b09effee23338a770 to your computer and use it in GitHub Desktop.
Create Nimble Volumes and VMware vSphere Datastores
$vmhost = 'esxi-01.domain.local'
$vcenter = 'vcenter.domain.local'
$vcenter_user = 'administrator@vsphere.local'
# Save encrypted password to a file
# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File vcenter-password.txt
$vcenter_password = Get-Content vcenter-password.txt | ConvertTo-SecureString
$nimble_mgmt_address = '10.1.1.1'
$nimble_user = 'admin'
# Save encrypted password to a file
# Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File nimble-password.txt
$nimble_password = Get-Content nimble-password.txt | ConvertTo-SecureString
$datastores = Import-Csv 'Nimble Datastores.csv'
$initiator_group = 'VMware-ESXi-Hosts'
$performance_policy = 'VMware ESX 5'
$volumes = @()
# Connect to Nimble
$nimble_creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $nimble_user, $nimble_password
Connect-NSGroup -Group $nimble_mgmt_address -credential $nimble_creds | Out-Null
# Connect to vCenter
if ($global:defaultviservers -eq $null) {
$vcenter_creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $vcenter_user, $vcenter_password
Write-Host "Connecting to $vcenter"
Connect-VIServer -Server $vcenter -Credential $vcenter_creds
}
# Create new volumes
$initiator_group_id = Get-NSInitiatorGroup -Name $initiator_group | Select-Object -ExpandProperty Id
$performance_policy_id = Get-NSPerformancePolicy -Name $performance_policy | Select-Object -ExpandProperty Id
foreach ($ds in $datastores) {
$volume = New-NSVolume -Name $ds.Name -Size $ds.Size -Multi_Initiator:$true -PerfPolicy_Id $performance_policy_id
# Set access control record
New-NSAccessControlRecord -Vol_Id $volume.id -Initiator_Group_Id $initiator_group_id | Out-Null
$volumes += $volume
}
# Create new datastores
Get-VMHostStorage -VMHost $vmhost -RescanAllHba
foreach ($v in $volumes) {
$canonical_name = "eui.$($v.serial_number)"
New-Datastore -Name $v.Name -Path $canonical_name -Vmfs -VMHost $vmhost
}
Name Size
Test-Datastore 307200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment