jeff5144
Contributor
Contributor

Adding NFS shares accross multiple ESX servers.

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!

0 Kudos
20 Replies
LucD
Leadership
Leadership

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


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

0 Kudos
jeff5144
Contributor
Contributor

The CSV file will contain the host name and IP address in which we'll inject a different user account.

0 Kudos
LucD
Leadership
Leadership

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.


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

0 Kudos
jeff5144
Contributor
Contributor

I've been trying your script above and it keeps giving me the error at : Connect-VIServer -Server &lt;&lt;&lt;&lt; $_.MyVC

*

C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; Connect-VIServer -Server $_.MyVC*

Connect-VIServer : Cannot validate argument on parameter 'Server'. The argument cannot be null or empty.

At line:1 char:25

+ Connect-VIServer -Server &lt;&lt;&lt;&lt; $_.MyVC

  • + CategoryInfo : InvalidData: (Smiley Happy , ParameterBindingValidationException*

  • + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.ConnectVIServer

*

0 Kudos
LucD
Leadership
Leadership

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.


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

0 Kudos
jeff5144
Contributor
Contributor

Its exactly as below, I'm testing this against 2 hosts for the time being.

Thank you for assisting. Another question if you want to add multiple datastores?

servername.domain.com

servername.domain.com

0 Kudos
LucD
Leadership
Leadership

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.

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


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

0 Kudos
jeff5144
Contributor
Contributor

Yea, I tried breaking this down and I get the CSV file imported succesfully.

Here is what I am doing to troubleshoot.

This part works fine, when I run this it returns the 2 host servers in the csv file

Import-Csv "C:\scripts\input.csv" -Header MyVC

This part errors out:

*%{Connect-VIServer* -Server $_.MyVC Get-VmHost*

*

0 Kudos
LucD
Leadership
Leadership

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.


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

0 Kudos
ablej
Hot Shot
Hot Shot

Getting the following error. Any Ideas?

New-Datastore : A parameter cannot be found that matches parameter name 'RemoteHost'.

At line:3 char:102






David Strebel

www.vmwaregeek.com

If you find this information useful, please award points for "correct" or "helpful"

David Strebel www.david-strebel.com If you find this information useful, please award points for "correct" or "helpful"
0 Kudos
admin
Immortal
Immortal

Should be -nfshost and -path. Maybe Luc had some customizations to his environment?

=====

Carter Shanklin

Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]

0 Kudos
LucD
Leadership
Leadership

No customisation, this came from an old VITK build.

See also .

And from a ThinApp-ed version in my VITK/PowerCLI museum.

Btw that build runs apparently without a problem on Windows 7 64-bit.

Compliments to the developers Smiley Happy

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
justinsmith
Enthusiast
Enthusiast

Didnt mean to steal the original post, but Im looking to do something very similar... but to a specific Cluster instead of an entire vCenter server.

I have about 6 ESX 4.1 hosts that I need to add roughly 8 NFS datastores EACH.... is there an easy way to do this? I dont need an excel spreadsheet since I already know the vCenter server and the Cluster name. I would even be happy to add all the NFS shares to an individual ESX host... but adding them to the cluster would be much cooler Smiley Happy 

0 Kudos
LucD
Leadership
Leadership

You can get all the hosts in the cluster and then execute the NFS share against each one, like this

Get-Cluster MyCluster | Get-VMHost | New-Datastore -Name DSx -Nfs -Path '/some/path' -NFSHost "nfsserver'

You can do this 8 times for each NFS export, or you can use a foreach code block

Get-Cluster MyCluster | Get-VMHost | %{
     New-Datastore -VMHost $_ -Name DS1 -Nfs -Path '/some/path1' -NFSHost "nfsserver1'
     New-Datastore -VMHost $_ -Name DS2 -Nfs -Path '/some/path2' -NFSHost "nfsserver2'
     ....
}


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

0 Kudos
justinsmith
Enthusiast
Enthusiast

Looks great... but how would I go about adding multiple lines to the script for adding multiplte datastores to the one cluster?

Update: Its asking for a username/password... not sure wif thats for the storage or vCenter or? When adding DS's in vCenter, it doesnt ask for a username/password...

0 Kudos
LucD
Leadership
Leadership

Did you do a Connect-VIServer -Server <your-VC> first ?

Most pieces of code in the Community don't mention it, but you should be connected.

The 2nd example shows how to use the foreach codeblock.

In there you can have multiple lines.


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

0 Kudos
justinsmith
Enthusiast
Enthusiast

Yes Im connected to the vCenter prior to running the command..

I've tried using VESI Script Editor and it prompts for a username/password and I've also tried running the command from vSphere PowerCLI and it asks for a username/password.

See below:

cmdlet New-Datastore at command pipeline position 3
Supply values for the following parameters:
Username:
Password:

0 Kudos
LucD
Leadership
Leadership

Oops, I forgot the -Nfs switch on the New-Datastore cmdlet.

Code above has been updated.


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

0 Kudos
justinsmith
Enthusiast
Enthusiast

I know, and I added it Smiley Happy 

This is what I'm running...

Get-Cluster Test-Dev-Pod1-Intel | Get-VMHost | New-Datastore -Nfs -Name 6070_VM_Prod_vol5 -Path '/vol/VM_Prod_vol6' -NFSHost 10.200.254.40

0 Kudos