This may not *technically* be PowerCLI specific, but I'm using PowerShell to interact with a VMware product, so I'm hoping it's related enough to qualify. (Also, I did submit to the API Community, but very small numbers there)
I'm sure I'm just overlooking something because surely they wouldn't allow you to create Custom Properties on so many entities, but not provide a mechanism to access those properties programmatically.
I've got some PowerShell that is calling the vRA REST API, and getting information about some VMs (sample below).
$authPostContentText = @{
"username"=[username]
"password"=[password]
"tenant"=[tenant]
}
$authPostContent = $authPostContentText | ConvertTo-Json
$authHeaders = @{"Content-Type"="application/json"}
$authResponse = Invoke-RestMethod -Uri $authURL -Method Post -Body $authPostContent -Headers $authHeaders
$token = $authResponse.ID
$restHeaders = @{"Content-Type"="application/json";"Authorization"="Bearer $token"}
$response = Invoke-RestMethod -Uri $resourceURL -Method Get -Headers $restHeaders
echo $response.content[0]
<#
@type : CatalogResource
id : bca1f1ce-50de-4288-ac55-12e0a9b10fe8
iconId : cafe_default_icon_genericCatalogItem
resourceTypeRef : @{id=Infrastructure.Virtual; label=Virtual Machine}
name : testVMwithCustomProperties
description : 1234
status : ACTIVE
catalogItem : @{id=fff8944a-af62-4edf-9ee6-8de2f424e2c2; label=Server 2012 R2 (usb)}
requestId : b1a9f791-65af-4075-8e0e-61864f611fdf
providerBinding : @{bindingId=3a0e1795-df96-4be2-b339-d74751891357; providerRef=}
owners : {@{tenantName=[tenant]; ref=[user]@domain; type=USER; value=[user]}}
organization : @{tenantRef=[tenant]; tenantLabel=[tenantLabel];
subtenantRef=5082ded7-fa03-4664-c620-35dfaf177fd0; subtenantLabel=[...]}
dateCreated : 2015-07-29T16:34:28.072Z
lastUpdated : 2015-07-29T16:34:32.203Z
hasLease : True
lease : @{start=2015-07-29T16:32:55.000Z}
leaseForDisplay :
hasCosts : True
costs : @{leaseRate=}
costToDate : @{type=money; currencyCode=USD; amount=0.0}
totalCost :
childResources : {}
operations :
forms : @{catalogResourceInfoHidden=True; details=}
resourceData : @{entries=System.Object[]}
#>
However, there doesn't seem to be an array of CustomProperty references associated with this VM or anything. And I seem to be unable to locate where to access custom properties of a VM (or a Reservation or Business Group, etc) through the REST API. Is that really not presented/available information?
Any help or guidance would be appreciated.
Did you already drill down under resourceData ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
> $response.content[0].resourceData
entries
-------
{}
EDIT:
Just to expand on this, if I add the ID to the URL
https://[vraserver]/catalog-service/api/consumer/resources/bca1f1ce-50de-4288-ac55-12e0a9b10fe8
I can get details on that specific VM. I'm looking for a CustomProperty named '[orgAbbr].TestCustomProperty' yet all I get is this: http://pastebin.com/sYuf9dK9
Did you ever get this answered? I'm looking for the same information and I am really frustrated by the lack of documentation and examples. Any insight you can provide will be appreciated.
Hello,
I'm also looking for the CustomPropeties via RestAPI.
I checked the RessourceData as mentions from LucD but there are not the expected Values...
$resourceURL = "https://vraFQDN/catalog-service/api/consumer/resources/0009672a-4fef-449b-97eb-e27dc31ce3d2"
$restHeaders = @{"Content-Type"="application/json";"Authorization"="Bearer $token"}
$response = Invoke-RestMethod -Uri $resourceURL -Method Get -Headers $restHeaders
$ressoiurceData = $response.resourceData
via vCO there is a way:
var vCACHost = Server.findAllForType( "vCAC:VCACHost","" )[0];
var instanceUuid = vCenterVm.config.instanceUuid;
var vraVm = Server.findAllForType("vCAC:VirtualMachine", "VMUniqueID eq '" + instanceUuid + "'");
var vmEntity = vraVm[0].getEntity();
var vCACMachineEntityProperties = vmEntity.getLink(vCACHost,"VirtualMachineProperties");
var vCACVmProperties = new Properties();
for each (var vCACMachineEntityProperty in vCACMachineEntityProperties) {
vCACVmProperties.put(vCACMachineEntityProperty.getProperty("PropertyName"),vCACMachineEntityProperty.getProperty("PropertyValue"));
}
Alle Eigenschaften einer vRealize Automation VM anzeigen | my cloud-(r)evolution
Oh no, Java code in the PowerCLI Community :smileyshocked:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry for that
But at the moment I dont figured out a PowerShell / RestAPI way.
I've not been able to get custom property data via the vRA REST API, but I have been able to get it via the IaaS oData API. I've got an example function in a Gist here. I've only tested this on 5.2.
It's not particularly pretty, but (assuming you use the -IncludeCustomProperties switch) you should be able to access the custom properties of the returned machine objects.
Also, be aware that it's pretty slow; and remember to specify your IaaS server, not your vRA server.