VMware Cloud Community
Jason_tee
Contributor
Contributor

Try to create new VM when connected to multiple servers

Hi,

I'm trying to combined several scripts into one and make it automated.

Currently in our environment, we have 2 different Vcenter, so I use "Set-PowerCLIConfiguration -DefaultVIServerMode multiple -confirm:$false" to connect 2 servers at the beginning of the script.

I then run into issue that the script is not able to find the right location to create the new VM.

This is the current script does:

New-VM -name $Name -ResourcePool $pool -datastore $LUN -location $folder -template $Template

I tried to change it to:

New-VM -name $Name -Server $server -ResourcePool $pool -datastore $LUN -location $folder -template $Template

But I get error below.

New-VM The method of operation is not implemented.

Any help or suggestion would be very much appreciated.

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Can you provide us a bit more background info?

What vCenters are you connected to?

What does $global:defaultviservers show?

What is in $server?

Perhaps all the commands you entered, and a screenshot of the session?


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

Reply
0 Kudos
Jason_tee
Contributor
Contributor

Thanks for the quick reply.

It's vcenter 5.5 environment, the script is run via powercli.

$global:defaultviservers will list down the 2 servers I connected to.

server1 443 myID

server2 443 myID

$server is either server1 or server2 depending on the condition check during the script run.

It will check based on the datastore, VLAN and if it fit to be in server1 then $server = "server1" or vice versa.

Hope this explain little bit more.

Reply
0 Kudos
LucD
Leadership
Leadership

These server1 and server2 are vCenters, correct?

Is the account with which you connect authorised to create VMs?

The servers are licensed I assume?

I would still like to see a screenshot of the command and the error it produces.

After the error, can you display the content of $error[0]?


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

Reply
0 Kudos
Jason_tee
Contributor
Contributor

Yes, the server1 and server2 are vCenters (there are just names I come up with, from screenshot below you can see the actual server name).

My account that used to run the script do have full access to create VM.

It is licensed server/vcenter.

Error as below, I write-host the actual line I'm running for your references.

$error[0] shown the same error.

Capture.PNG

pastedImage_1.png

Reply
0 Kudos
LucD
Leadership
Leadership

I forgot to ask earlier, which PowerCLI and PowerShell version are you using?

From the ErrorAction Stop I assume you are executing this in a Try-Catch construct.

Is that correct?

Did you already try with leaving the -ErrorAction Stop out of the New-VM, and perhaps adding the Verbose switch?

Anything from that?

It could also be useful to have a look at the vpxd log at the time when the exception occurs.

There might be some additional info in there.


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

Reply
0 Kudos
Jason_tee
Contributor
Contributor

I tried to remove the -Server from the script and turns out it work and able to create it correctly on each of the vcenter based on the datastore I put in so issue solved now.

Thank you for all the effort to assist.

Reply
0 Kudos