VMware Cloud Community
Rakesh_098
Contributor
Contributor

Adding a NFS data store across multiple esx hosts

Hi Folks,

I am looking for a script which will mount a NFS data store across all the esx hosts in the cluster. I tried something below but it didn't work.

$esx = (Get-Content esx_servers.txt)

$Host_Name = (Read-Host "Enter the server ")

$Path = (Read-Host "Enter the path (ex:/vol/vol/ds_name):")

$Name = (Read-Host "Enter the name of the datastore:")

foreach($server in $esx){

Get-VMHost $server | New-Datastore -Nfs -NfsHost $Host_Name -Path $Path -Name $Name

}

Please let me know if you guys have any other idea.

0 Kudos
5 Replies
LucD
Leadership
Leadership

That looks like it should work.

Did you get any error messages ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Rakesh_098
Contributor
Contributor

I dont find error, the script is executing successfully but mounting task is not getting started. Not sure if i have to edit somewhere other than storage server name/path/DS name.

0 Kudos
LucD
Leadership
Leadership

Does it work when you do it step by step ?

$esx = Get-VMHost YourServer

New-Datastore -VMHost $esx -Nfs -NfsHost YourNFSServer -Path Path -Name YourName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Rakesh_098
Contributor
Contributor

Here is the error what i am getting.

$esx = (Get-Content D:\DS\esx_servers.txt)

$Host_Name = (Read-Host "TESTPETPDFSMPN002-vlan242.MKS.com")

$Path = (Read-Host "/vol/vmds_sata_farm200_004")

$Name = (Read-Host "vmds_sata_farm200_004")

foreach($server in $esx){

Get-VMHost $server | New-Datastore -Nfs -NfsHost $Host_Name -Path $Path -Name $Name

}

PowerCLI D:\DS> & '.\DS add.ps1'

TESTPETPDFSMPN002-vlan242.MKS.com:

/vol/vmds_sata_farm200_004:

vmds_sata_farm200_004:

New-Datastore : Cannot validate argument on parameter 'NfsHost'. The argument

is null or empty. Supply an argument that is not null or empty and then try

the command again.

At D:\DS\DS add.ps1:7 char:50

+ Get-VMHost $server | New-Datastore -Nfs -NfsHost $Host_Name -Path $Path

-Name $N ...

+                                                  ~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [New-Datastore], ParameterBindi

   ngValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

   ation.ViCore.Cmdlets.Commands.Host.NewDatastore

0 Kudos
LucD
Leadership
Leadership

Ok, the hostname seems to be the problem.

Can you try just assigning the value to the variable ?

$Host_Name = 'TESTPETPDFSMPN002-vlan242.MKS.com'

And perhaps the same for the other variables ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos