PowerCLI 5.0.1 delivered new vCloud Director functionality including a cmdlet named Search-Cloud. If you’ve taken a look at Get-Help Search-Cloud, you’ll see a parameter named -QueryType used to “Specify what types of objects you want to search for”. That’s great, but what types of objects *can* you search for? The help, sadly, isn’t very helpful.
There are a couple different ways to find out. One of them is specific to PowerCLI 5.0.1 and is the Cmdlet Reference. By drilling into the All Cmdlets section and locating Search-Cloud, you’ll see that the parameter named QueryType is of the type QueryType, which is a .NET Enum. Click on the QueryType and you’ll see all the cool things that you can search for using Search-Cloud. Very nice!
AdminAllocatedExternalAddress |
AdminCatalogItem |
AdminCatalog |
AdminGroup |
AdminMedia |
AdminOrgNetwork |
AdminShadowVM |
AdminTask |
AdminUser |
AdminVAppNetwork |
AdminVApp |
AdminVAppTemplate |
AdminVM |
AdminVdc |
AllocatedExternalAddress |
BlockingTask |
CatalogItem |
Catalog |
Cell |
DatastoreProviderVdcRelation |
Datastore |
DvSwitch |
Event |
Group |
Host |
Media |
NetworkPool |
Network |
OrgNetwork |
Org |
OrgVdc |
OrgVdcResourcePoolRelation |
Portgroup |
ProviderVdcResourcePoolRelation |
ResourcePool |
Right |
Role |
StrandedUser |
Task |
User |
VAppNetwork |
VAppOrgNetworkRelation |
VApp |
VAppTemplate |
VM |
VMWProviderVdc |
VirtualCenter |
;
There are a few other ways to figure out what the type of parameter -QueryType is, and the expected values. One of them is quite simple, use an invalid -QueryType.
[code]
PS C:\>; Search-Cloud -QueryType me
Search-Cloud : Cannot bind parameter ‘QueryType’. Cannot convert value "me" to type "VMware.VimAutomation.Cloud.View
s.QueryType" due to invalid enumeration values. Specify one of the following enumeration values and try again. The p
ossible enumeration values are "User, AdminVAppNetwork, AdminUser, BlockingTask, Cell, Host, AdminCatalogItem, Vm, A
dminCatalog, Group, AllocatedExternalAddress, OrgVdcResourcePoolRelation, AdminVApp, DvSwitch, Organization, VAppTem
plate, AdminAllocatedExternalAddress, OrgNetwork, Catalog, VirtualCenter, ResourcePool, Right, StrandedUser, Portgro
up, AdminVM, Media, AdminVAppTemplate, AdminOrgVdc, OrgVdc, CatalogItem, Event, VApp, AdminOrgNetwork, VAppNetwork,
AdminShadowVM, Datastore, ProviderVdc, DatastoreProviderVdcRelation, AdminMedia, ExternalNetwork, NetworkPool, Admin
Group, Task, AdminTask, VAppOrgNetworkRelation, Role, ProviderVdcResourcePoolRelation".
At line:1 char:24
+ Search-Cloud -QueryType <;<;<;<; me + CategoryInfo : InvalidArgument: (:) [Search-Cloud], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.Cloud.Commands.Cmdlets.SearchCloud [/code]
Another would be to find the ParameterType, which shows us it’s VMware.VimAutomation.Cloud.Views.QueryType. This can be accomplished in steps:
[code] PS C:\>; Get-Command search-Cloud | Select-Object -ExpandProperty Parameters
Key Value
— —–
Name System.Management.Automation.ParameterMetadata
Filter System.Management.Automation.ParameterMetadata
QueryType System.Management.Automation.ParameterMetadata
Property System.Management.Automation.ParameterMetadata
Server System.Management.Automation.ParameterMetadata
Verbose System.Management.Automation.ParameterMetadata
Debug System.Management.Automation.ParameterMetadata
ErrorAction System.Management.Automation.ParameterMetadata
WarningAction System.Management.Automation.ParameterMetadata
ErrorVariable System.Management.Automation.ParameterMetadata
WarningVariable System.Management.Automation.ParameterMetadata
OutVariable System.Management.Automation.ParameterMetadata
OutBuffer System.Management.Automation.ParameterMetadata
[/code]
And then:
[code]
PS C:\>; (Get-Command search-Cloud | Select-Object -ExpandProperty Parameters).QueryType
Name : QueryType
ParameterType : VMware.VimAutomation.Cloud.Views.QueryType
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic : False
Aliases : {}
Attributes : {__AllParameterSets, System.Management.Automation.ValidateNotNullOrEmptyAttribute}
SwitchParameter : False
[/code]
And
[code]
PS C:\>; (Get-Command search-Cloud | Select-Object -ExpandProperty Parameters).QueryType.ParameterType
IsPublic IsSerial Name BaseType
——– ——– —- ——–
True True QueryType System.Enum
[/code]
Now that we know it’s an enum, we can do a couple different things. The code below will list out all the names in the enum.
[code]
[Enum]::GetNames("VMware.VimAutomation.Cloud.Views.QueryType")
[/code]
We’ll get effectively the same information back in this way, too.
[code]
[VMware.VimAutomation.Cloud.Views.QueryType] | Get-Member -Static -MemberType Property
[/code]
Ronald Rink says
Maybe you could also mention that Search-Cloud uses the query service. It use less API queries than a full-blown Get-Org command for example, and is therefore magnitudes faster than the other vCD Get-* CmdLets – this is where Search-Cloud is really way cooler …
Alan Renouf says
Search-Cloud -Querytype [TAB]
Thats what I normally do and it scrolls through the different options 😉
Jake says
Powershell 3, FTW! 😀
Jake says
You can also pipe the result of Search-Cloud to Get-CIView, if you want the actual object from the search results. This is useful if there is no direct cmdlet to get certain objects
Search-Cloud -querytype VirtualCenter | Get-CIView