VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
9 Replies Last post: Jun 15, 2009 9:51 PM by LucD  

Adding NFS shares accross multiple ESX servers. posted: Jun 12, 2009 2:35 PM

Click to view jeff5144's profile Novice 6 posts since
Apr 10, 2009

Can anyone assist with using the powershell command to add mutiple NFS shares accross multiple virtual centers reading from a CSV file.

Task
Create powershell command to look to a CSV file with a list of ESX hosts in different virtual center servers.

Add 4 NFS datastores.

Any assistance would be much appreciated!


Re: Adding NFS shares accross multiple ESX servers.

1. Jun 12, 2009 3:41 PM in response to: jeff5144
Click to view LucD's profile Champion 2,435 posts since
Oct 31, 2005
Could you perhaps describe what is in the CSV file ? VC names and/or ESX hostnames ?
And where will get the account/password to logon to the VCs ? Or will this go via pass through with the account that runs the script ?

Adding a NFS datastore can be done with the New-Datastore cmdlet.
See NFS mount on multiple hosts

Re: Adding NFS shares accross multiple ESX servers.

3. Jun 15, 2009 11:11 AM in response to: jeff5144
Click to view LucD's profile Champion 2,435 posts since
Oct 31, 2005
I'll assume that the CSV file contains the names of the VCs.
Then you can do something like this provided you have a header row in the CSV that says "VCname"
Import-Csv "C:\cvname.csv" | %{
	Connect-VIServer -Server $_.VCname
	Get-VmHost | New-Datastore -Nfs -Name NFSds -Path NFSds -RemoteHost <NFSserver> -RemotePath <NFSexport>
}

If there is no header row you can do
Import-Csv "C:\cvname.csv" -Header MyVC | %{
	Connect-VIServer -Server $_.MyVC
	Get-VmHost | New-Datastore -Nfs -Name NFSds -Path NFSds -RemoteHost <NFSserver> -RemotePath <NFSexport>
}


This assumes that the account with which you execute the script has rights on all the VCs.
The Connect-ViServer uses passthrough authentication.

Re: Adding NFS shares accross multiple ESX servers.

5. Jun 15, 2009 2:00 PM in response to: jeff5144
Click to view LucD's profile Champion 2,435 posts since
Oct 31, 2005
It looks like the import form the CSV file is not functioning.
Could you perhaps include a screenshot of the first few lines of this VC file?
You can scramble the text if you need to, I just want to see the layout.

Re: Adding NFS shares accross multiple ESX servers.

7. Jun 15, 2009 2:28 PM in response to: jeff5144
Click to view LucD's profile Champion 2,435 posts since
Oct 31, 2005
There must be something wrong but I can't see what it is.
This is from a run of such a script on my test PC.
Note that I replaced the Connect-ViServer by a Write-Host to see the variable.

importCSV.png

testCSV.png

If you want to add multiple NFS datastores you have to repeat the line with the New-Datastore cmdlet.

Re: Adding NFS shares accross multiple ESX servers.

9. Jun 15, 2009 9:51 PM in response to: jeff5144
Click to view LucD's profile Champion 2,435 posts since
Oct 31, 2005
Is there really a Get-VmHost on the Connect-ViServer line ?
It should be
Import-Csv "C:\scripts\input.csv" -Header MyVC | %{
   Connect-VIServer -Server $_.MyVC
...
}

Perhaps you could PM me the script your are trying to use.
The forum SW sometimes scrambles code one inserts in a post.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities