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
}
Try like this
$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
You mean like this?
$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
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
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
I have following data in CSV file for now.
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
i double checked, no blanks
The error message states that the Name property is empty.
What does this return
$rows = Import-csv -Path $Dspath
$rows.Count
$rows
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is the output, am seeing..
It's missing the $rows.Count.
Just run
$rows = Import-csv -Path $Dspath
$rows.Count
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As an alternative, check what this returns.
$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
below is the output
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
but the datastorename in csv file mentioned which is showing in image as well next to Name:
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
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.
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
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
}
Try like this
$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
any possiblities to update the completed NFS datastore mount in the log file.
that helps to check what are added