VMware Cloud Community
shatztal
Contributor
Contributor
Jump to solution

how to Set Customfields to Datacenter?

hello,

i want to add custom fields to the Datacenter view , when i do it for hosts and vms it works fine , but to the Datacenter it does not work,

is it event possible to do that ?

thanks in advance

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Yes, you can add custom fields to the datacenter view. The only problem is that you will not see them in the vCenter client. This seems a restriction of the vCenter client to me. But you can use them in PowerCLI.

To following PowerCLI script adds a custom field named Location to the datacenter view. It then retrieves the first datacenter. Gives the value Amsterdam to the location field of this datacenter. And finaly retrieves all the custom fields for this datacenter.

New-CustomAttribute -Name Location -TargetType Datacenter
$Datacenter = Get-Datacenter | Select-Object -First 1
Set-Annotation -Entity $Datacenter -CustomAttribute Location -Value Amsterdam
Get-Annotation -Entity $Datacenter

If you use the New-CustomField cmdlet instead of the New-CustomAttribute cmdlet the syntax is slighty different:

$Datacenter = Get-Datacenter | Select-Object -First 1
New-CustomField -Entity $Datacenter -Name Country -Value "The Netherlands"
Get-Annotation -Entity $Datacenter

Regards, Robert

Added the New-CustomField example.

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Yes, you can add custom fields to the datacenter view. The only problem is that you will not see them in the vCenter client. This seems a restriction of the vCenter client to me. But you can use them in PowerCLI.

To following PowerCLI script adds a custom field named Location to the datacenter view. It then retrieves the first datacenter. Gives the value Amsterdam to the location field of this datacenter. And finaly retrieves all the custom fields for this datacenter.

New-CustomAttribute -Name Location -TargetType Datacenter
$Datacenter = Get-Datacenter | Select-Object -First 1
Set-Annotation -Entity $Datacenter -CustomAttribute Location -Value Amsterdam
Get-Annotation -Entity $Datacenter

If you use the New-CustomField cmdlet instead of the New-CustomAttribute cmdlet the syntax is slighty different:

$Datacenter = Get-Datacenter | Select-Object -First 1
New-CustomField -Entity $Datacenter -Name Country -Value "The Netherlands"
Get-Annotation -Entity $Datacenter

Regards, Robert

Added the New-CustomField example.

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
shatztal
Contributor
Contributor
Jump to solution

Thank you very much for the help, the Customfield didn't work as i said before but because of you i remebered that there is also set-annotaion

and with that i do see the value in the vClient.

so thanks for the TIP it helped me at the end .

0 Kudos