Along with the CmdLets in “VMware.VimAutomation.Cloud” you will find a CmdLet that is called “Search-Cloud”. In fact this is one of the most powerful CmdLets in ypur arsenal of vCD CmdLet tools. It is especially useful as it uses the new Query Service of vCD and is thus much faster than the other traditional Get-* CmdLets. The tradeoff is that is does not return all information of the object you search. However, most of the time I find that I really do not need them anyway. But there is a workaround: One of the properties you get always returned is the “id” (or “urn”) of the vCD object and with that you can use the other Get-* CmdLets via the “-id” switch to return a full object.
So, for example, you could write:
$Org = Search-Cloud -QueryType Organization -Name "Appclusive"; $OrgFull = Get-Org -id $Org.id;
One of your common tasks might be traversing the vCD hierarchy, starting with Orgs down to VMs. To efficiently search (or query) these objects you need to specify a filter condition in addition to the QueryType:
$Org = Search-Cloud -QueryType Organization -Name "Appclusive"; $aOvdcs = Search-Cloud -QueryType AdminOrgVdc -Filter "org==$($Org.id)"; $Ovdc = $aOvdcs; $aVApps = Search-Cloud -QueryType AdminVApp -Filter "vdc==$($Ovdc.id)"; $VApp = $aVApps;
However when you come down to a VApp you have to specify “container” instead of “VApp” as the filter condition.
$aVms = Search-Cloud -QueryType AdminVM -Filter "container==$($VApp.id)";
In the background Search-Cloud effectively uses the vCD REST Query Service. So if you want a full list of possible verbs you just consult the vCD REST API documentation. And if in doubt you can always refer to the request log in vCD to see the actual REST calls.
As a sidenote: querying 200 organisations via “Get-Org” can take you around 30s, whereas “Search-Cloud” will probably return in less than 1s.
Leave a Reply