VMware Cloud Community
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

NFS mount point script

am trying below script to add nfs mount point to the esxi hosts which am mentioniong in ds.csv file

instead in csv am looking to ask on which host mount point to be added.

$Dspath=c:\temp\ds.csv

$Dsconf= Import-csv $Dspath

write-host "enter esxi host name"

foreach($ds in $Dsconf)

{

New-Datastore -Nfs -Name $ds.name -path $ds.path -nfshost $ds.nfshost

}

pastedImage_0.png

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

$Dspath = "c:\temp\ds1.csv"

$Dsconf = Import-csv $Dspath


Get-Cluster -Name "Staging" | Get-VMHost |

ForEach-Object -Process {

   foreach ($ds in $Dsconf)

   {

     New-Datastore -VMHost $_ -Nfs -Name $ds.name -path $ds.path -nfshost $ds.nfshost

   }

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
30 Replies
LucD
Leadership
Leadership
Jump to solution

You mean like this?

$Dspath = c:\temp\ds.csv

$Dsconf = Import-csv $Dspath

$esxName = Read-Host "enter esxi host name"


foreach ($ds in $Dsconf)

{

   New-Datastore -VMHost $esxName -Nfs -Name $ds.name -path $ds.path -nfshost $ds.nfshost

}


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

am seeing following error and append log file with a message "Name" added successfully on esxi host<host name>

in csv file i have

nfshost                       path                       name

NFSServerIP       10.X.X.X/Nfs_ds1      Nfs1_ds1

NFSServerIP       10.X.X.X/Nfs_ds2      Nfs1_ds2

NFSServerIP       10.X.X.X/Nfs_ds1      Nfs1_ds1

NFSServerIP       10.X.X.X/Nfs_ds2      Nfs1_ds2

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to be an issue in your CSV file.
Is there perhaps a blank line in the CSV?


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

I have following data in CSV file for now.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's not what I asked.
I asked if there was a blank line in your CSV


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

i double checked, no blanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The error message states that the Name property is empty.

What does this return

$Dspath = c:\temp\ds.csv

$rows = Import-csv -Path $Dspath

$rows.Count

$rows


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

This is the output, am seeing..

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's missing the $rows.Count.
Just run

$Dspath = c:\temp\ds.csv

$rows = Import-csv -Path $Dspath

$rows.Count


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

As an alternative, check what this returns.

$Dspath = 'c:\temp\ds.csv'

$Dsconf = Import-csv $Dspath

$esxName = Read-Host "enter esxi host name"

foreach ($ds in $Dsconf)

{

   Write-Host "Name: $($ds.Name)  Path: $($ds.Path)  Host: $($ds.NfsHost)"

}


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

below is the output

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then I don't understand the error you are getting.
That clearly says that the datastorename, from $ds.Name, is empty.


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

but the datastorename in csv file mentioned which is showing in image as well next to Name:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Exactly, but on the New-Datastore cmdlet it apparently isn't.

Btw, did you try to run that snippet again in the mean time?
Why does it seem to have the same error 3 times?

I can't see how this happens with a CSV with only 1 row in it.


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

now i see different message.

I see already datastore which am trying to add to the host is added to one of the host out of two hosts.(currently cluster has two esxi hosts, on one host already nfs datastore is added, am trying to add nfs datastore to second host), going further new hosts will be added to the cluster and i have to add the nfs datastores to all the hosts in the cluster.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This seems to be missing permissions on the NFS export for that specific ESXi node.

You will have to talk with whoever manages that NFS export.


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

okay, i will talk to them.

how to modify the same script for adding NFS datastore to entire cluster.

$Dspath = "c:\temp\ds1.csv"

$Dsconf = Import-csv $Dspath

$esxName = Read-Host "enter esxi host name"

$cluster=get-cluster "Staging"

foreach ($ds in $Dsconf)

{

   New-Datastore -VMHost $esxName -Nfs -Name $ds.name -path $ds.path -nfshost $ds.nfshost

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$Dspath = "c:\temp\ds1.csv"

$Dsconf = Import-csv $Dspath


Get-Cluster -Name "Staging" | Get-VMHost |

ForEach-Object -Process {

   foreach ($ds in $Dsconf)

   {

     New-Datastore -VMHost $_ -Nfs -Name $ds.name -path $ds.path -nfshost $ds.nfshost

   }

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

any possiblities to update the completed NFS datastore mount in the log file.

that helps to check what are added

0 Kudos