Using PowerCLI to add a datastore to VMware hosts

Using PowerCLI to add a datastore to VMware hosts

Using PowerCLI to add a datastore to VMware hosts

The administrative task of adding a new datastore to all hosts in a VMware Cluster using vSphere GUI increases as the number of hosts increases. Using PowerCLI, however, the workload is the same for configuring 2 or 200 hosts in a cluster.

The following few commands will add a new NFS based datastore to all hosts in a cluster.


foreach ($vmhost in (Get-VMHost -Location "[CLUSTERNAME]" )) {
New-Datastore -Nfs -VMHost $vmhost -Name [DATASTORENAME] -Path [PATH] -NfsHost [NFSHOST IP/FQDN]
}

Example of adding a new datastore called “store03”


foreach ($vmhost in (Get-VMHost -Location "Cluster01" )) {
New-Datastore -Nfs -VMHost $vmhost -Name store03 -Path /vol/vmware/datastore03 -NfsHost 10.1.1.2
}

Get vSphere PowerCLI 5.5 here: https://my.vmware.com/web/vmware/details?downloadGroup=PCLI550&productId=352