VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Create a new datacenter

Okay, this one should be really easy but it's got me stumped.

I want to create a new datacenter called VIRTUAL, but the issue is I am connected to two vCenters at the same time, so when I run the following command:

$datacenter = "VIRTUAL"
$location = Get-Folder -NoRecursion
New-DataCenter -Location $location -Name $datacenter

I'm getting:

New-Datacenter: Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer' required by parameter 'Location'. Specified method is not supported.

I suspect this is because I am connect to two vcenter as the same time, so the Get-Folder -NoRecursion command is returning two results:

PS C:\> Get-Folder -NoRecursion

Name Type
---- ----
Datacenters Datacenter
Datacenters Datacenter

I know the easy way to fix this would be to simply disconnect the vCenter I don't want to create the datacenter in, but this feels like a cop out, I'd really like to know how I can target the second vCenter I'm connected to. When I do a get-folder -NoRecursion | select * I notice that the only unique field appears to be the uid.

Can I use this to select the correct vCenter? Is there a better method I'm not thinking of?

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Judging from the UID I have the impression you want to create that new Datacenter at the root of the tree.
Then you could just use the name Datacenters.
Replace the Server value with the name of the correct vCenter.

$datacenter = 'VIRTUAL'
$location = Get-Folder -Name 'Datacenters' -Server 'MyVC'
New-DataCenter -Location $location -Name $datacenter

 


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

You can point to a specific vCenter by using the Server parameter.

But the error you are getting is because $location contains not a single Folder object, but is an array of Folder objects.
You have to make sure that $location points to a single $folder object.
Also the Location folder where you can create a Datacenter has to be a valid one to create a Datacenter.


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

0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

You're the man LucD! I tried supplying the -server parameter, but a location is still required and it was still throwing an error due to the location parameter still returning multiple results. The following works, but I'm still hoping to improve it:

#Use this to find the unique ID, copy and paste from the vcenter I want
#get-folder -NoRecursion | select Uid
$datacenter = "VIRTUAL"
$location = Get-Folder -NoRecursion | where {$_.Uid -eq "/VIServer=vsphere.local\administrator@vcdessloch.lebrine.local:443/Folder=Folder-group-d1/"}
New-DataCenter -Location $location -Name $datacenter

Surely there has to be a simpler way I'm not thinking of to get the UID? Or to just ensure that when I do a get-folder it only returns results from the vcenter I want, in this case vcdessloch.lebrine.local. Any suggestions?

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Judging from the UID I have the impression you want to create that new Datacenter at the root of the tree.
Then you could just use the name Datacenters.
Replace the Server value with the name of the correct vCenter.

$datacenter = 'VIRTUAL'
$location = Get-Folder -Name 'Datacenters' -Server 'MyVC'
New-DataCenter -Location $location -Name $datacenter

 


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