Hello LucD,
could you post the script to create vm from template.
Have a look at Example 10 of the New-VM cmdlet online help page.
Or do you have any specific requirements?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
well there is specific requirement .
if you can check following code .I have just encountered one hude script to deply vms from .csv file using template (which has two network adapters)
there is issue while configuring network . following is the code for configuring network adapter .
and below is the error.
to solve this currently i am making network1 and network2 as mandatory parameter like this but it is something extra iam doing as it also reads the .csv file .
Hope iam making sense here .
If I understand it correctly, you are trying to use splatting for the Set-NetworkAdapter.
And the hash table is build in the 1st piece of code.
Try like this (note the @ character when using splatting)
$VM | Get-NetworkAdapter | where{$_.Name -eq 'NetworkAdapter 2'} |
Set-NetworkAdapter @network
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
not sure of splatting . but checking .also there are two network adapters to be configured .
Since you are storing the parameters and their values in a hash table, I assumed you trying to use splatting.
The error actually says that it doesn't know how to convert from the hash table.
But try my suggestion.
In this specific error you are only configuring 1 vNIC ('Network adapter 2').
If you have more the concept should be the same.
I would need to see your complete script to check that.
Btw, it's handier if you attach code snippets as text files, not a screenshots.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
could you suggest how to pass the .csv file of diferent values .like name.numcpu,memory etc...
You can use the Import-Csv cmdlet for that.
Make sure that the column names in the CSV correspond with the property names you are using in your script.
# CSV has at least a column with the header VMName
# VMName
# VM1
# VM2
#
Import-csv -Path .\vm.csv -UseCulture | %{
Get-VM -Name $_.VMName
}
To show you a solution that integrates with your script, I would need to see the script
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The critical part is how you composed yuor CSV file.
Lines 53-76 describe exactly how the CSV should be composed.
The line number in the error you included earlier doesn't seem to correspond with the line numbers in the script you attached.
In the script line 337 handles 'Network adapter 1 ', not 'Network adapter 2' like the error message seems to indicate.
The attached script also clearly does splatting (as indicated by the @ in the following line).
$VM | Get-NetworkAdapter |where { $_.Name -eq 'Network adapter 1' } | Set-NetworkAdapter @network | Out-Null
In the error message you seem to have replaced that @ by a $.
The attached script in any case does not correspond with what you seem to be running.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your reply.
currently script fails while configuring second adapter .
error:null value
so i checked cSv and found only one ipaddress and corresponding network info is given .
iam not sure how to pass multiple values.
The original script you are using is not able to handle multiple vNICs and multiple IP addresses.
You obviously added logic to cope with a 2nd vNIC and IP address, your IPAddress2 and network2 additions.
In your effort to update the script, you apparently changed the splatting (@ changed in a $)
Did you do those changes to the script?
And did you change the CSV accordingly?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have deleted my additions.
also I changed $ to @ .
so the script which i posted is not able to handle multiple nics??
Not in its original form (as published on that website).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Somehow i think that splatting is used to solve this problem .
only thing which is pending is update .csv file accordingly which iam not sure how to pass multiple values.
When you changed the script (with properties like IPAddress2 and network2), did you also update the CSV accordingly.
And no, splatting has nothing to do with supporting a 2nd vNIC, you mistyped there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Well in that case i am thinking to make mandatory parameter for second nic the way we did it for ventername and credential .
i am able to think only this solution right now .do you have any other option like using import excel module instead of importing csv ??
No, it is quite simple, when you introduce new properties for the VM (like a 2nd vNIC), you have to add the corresponding columns in the CSV as well.
Nothing to do with CSV or XLSX
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i have following portion of .csv file these are the headers for network thier values not shown in following output.
now to facilitate vnic2 configuration i added same again with thier values.
so i added following in .csv file
is this how .csv should be modified??
Those 2 lines look exactly the same to me.
Perhaps dump the columns of the CSV than you can see what is there.
You can do something like this
Import-Csv -Path .\your-input.csv | gm
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference