Mount nfs datastore to multiple hosts in a cluster

From roonics
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This will get all the hosts in a cluster specified and mount the NFS datastore on all in the cluster.

You can either copy and paste the below to a .ps1 file and run the file or run the commands manually.

###########################################################################################################################
# EDIT THESE
###########################################################################################################################

$vcenter = "vcenter01"				# Change to the vCenter you wish to mount the NFS datastores to
$dc = "datacenter01"				# Change to datacenter name in vCenter
$cluster = "cluster01"				# Change to the cluster name you wish to mount the NFS datastores to
$datastorename = "nfs-datastore01"		# Change to name of datastore
$nfshostip = "10.10.10.10"			# Change to NFS host ip
$nfspath = "nfs-datastore01-san01"		# Change to NFS path

###########################################################################################################################
# DO NOT EDIT PAST THIS LINE
###########################################################################################################################

Connect-Viserver $vcenter
$esxs = Get-Datacenter $dc | Get-Cluster $cluster | Get-VMHost

 foreach ($esx in $esxs){ 
    $esx | New-Datastore -Nfs -Name $datastorename -NFSHost $nfshostip -Path $nfspath
    echo "NFS share added to $esx"
  }

‎<comments />