For anyone that’s ever been through the process of provisioning a new datastore to multiple ESX hosts, you know it can take some time. Below are the steps I use
- Create Volume on NetApp
- Set Security Style to Unix
- Enable Storage Efficiency
- Set NFS Export permissions to allow Read/Write + Root Permissions to all applicable hosts
- Mount datastores on ESXi hosts
For a handful of hosts this is fine, but adding it to anything more than 4-5 hosts is reaaally painful in my experience. Below is a script you can use to take care of these steps in one swipe.
Prerequisites:
The script requires an array of the NFS clients (read ESXi hosts) you want to connect the datastore to.
Example 1 – assign the array to a variable, and manually add it to a parameter
1
2
|
$ESXHosts = @("10.1.1.100","10.1.1.101","10.1.1.102")
Add-VolumeAndAddToESXi.ps1 -VolName Volume100 -VolSize 1.5T -filerIP 10.1.1.10 -aggrName aggr0 -ExportedHosts $ESXHosts -vCenter vcenter-site1
|
Example 2 – Create an array, and pipe it to the script
1 |
@("10.1.1.100","10.1.1.101") | Add-VolumeAndAddToESXi.ps1 -VolName Volume101 -VolSize 200G -filerIP 10.1.1.10 -aggrName aggr1 -vCenter vcenter-site1
|
Enjoy! Let me know if you have any challenges or questions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.49
Created on: 4/17/2014 10:39 PM
Created by: Jon Howe (www.cit3.net)
Filename: Add-VolumeAndAddToESXi.ps1
===========================================================================
.DESCRIPTION
Create Volume and add to all hosts in a vCenter server
.PARAMETER VolName
The Name of the Volume you want to create
.PARAMETER VolSize
The size of the newly created volume. Example: 10G, 1T, 100M
.PARAMETER filerIP
The IP Address of the filer
.PARAMETER aggrName
The aggregate that will contain the volume
.PARAMETER ExportedHosts
An array that contains IP Addresses of the ESXi hosts you want to provide NFS Export permissiosn to
.PARAMETER vCenter
The DNS or IP Address of the vCenter Server you want to provision the datastore to
.LINK
http://45.63.13.214/?p=584
.EXAMPLE
$ESXHosts = @("10.1.1.100","10.1.1.101","10.1.1.102")
Add-VolumeAndAddToESXi.ps1 -VolName Volume100 -VolSize 1.5T -filerIP 10.1.1.10 -aggrName aggr0 -ExportedHosts $ESXHosts -vCenter vcenter-site1
.EXAMPLE
@("10.1.1.100","10.1.1.101") | Add-VolumeAndAddToESXi.ps1 -VolName Volume101 -VolSize 200G -filerIP 10.1.1.10 -aggrName aggr1 -vCenter vcenter-site1
#>
Param (
[Parameter(Mandatory=$true)] [string]$VolName,
[Parameter(Mandatory=$true)] [string]$VolSize,
[Parameter(Mandatory=$true)] [string]$filerIP,
[Parameter(Mandatory = $true)] [string]$aggrName,
[Parameter(Mandatory=$true)] [string]$vCenter,
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] $ExportedHosts
)
#region Don't edit below here
###
##
#
$path = "/vol/" + $VolName
#Load Prerequisites
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction 'SilentlyContinue'
if (!(Get-Module DataOnTAP)) { Import-Module DataOnTAP }
# Connect to the filer
Write-Host "Enter credentials for the netapp filer"
$controller = Connect-NaController $filerIP -Credential (Get-Credential)
#Create the volume and set security style
New-NaVol -Aggregate $aggrName -Name $VolName -Size $VolSize -Controller $controller
Set-NaQtree -SecurityStyle UNIX -Path $path -Controller $controller
#Enable Storage Efficiency
enable-NaSis -Controller $controller -Volume (Get-NaVol -Name $VolName)
#Set NFS Export Permissions
Set-NaNfsExport -Path $path -ReadWrite $hosts -Root $hosts -Persistent
#Connect to vCenter Server
Write-Host "Enter credentials for the vCenter server"
Connect-VIServer -Credential (Get-Credential) -Server $vCenter
Get-Cluster -Name Production | Get-VMHost | New-Datastore -Nfs -Name $VolName -Path $path -NfsHost $NfsIP
#
##
###
#endregion Don't edit below here
|
– Jon