How To Use The Get-View Cmdlet In VMware PowerCLI

With VMware PowerCLI you can manage your vSphere environment and other VMware products. The PowerCLI cmdlets work with objects that contain properties for most of your daily needs as an administrator.

Internally vSphere works with objects that contain all the information used to configure and manage the environment. The Get-View cmdlet is one way of getting access to these internal vSphere objects.

In this video, we will show how you can access, and optimize this access, to the vSphere objects with the two most used parameter sets of the Get-View cmdlet. Throughout the video, we will use a property, namely the MultiHostAccess property on the Datastore object, to demonstrate this.

Hi in this video I'll show you how you can use the get view commandlet to get access to properties that are not available through regular powershell like commandlets. First, a quick look at our environment. As you can see on the right. We are using powershell 5 dot one powerCLI 10 dot 2 and we're connected to a VCenter. You get data store commandlet, it returns quite a bit of information about our data stores. As we can see in the output. There are things like the name the capacity? How much free space there is an even if the data storage is available or not. But if you look at the old line. API visual reference will notice that the data store object used internally has a lot more information that would get data store returns. In the following examples in this video. We will be using the multiple host access property, which is reachable through the summary property of the data store object. This property is something we can use to select candidate data store to create new VMS in a cluster. They get view commandlet comes with 4 parameter sets. In this video we'll be looking at the first 2 get view by VI object, and the get view parameters set. Get view by VI object is easy to use. We passed the object returned by get datastore through the pipeline to the get view commandlet. Together, the multiple host property. We need to expand the summary property that was returned on the data store object. If we know combine the above with the select object, and a calculated property. We can get a nice report with the candidate data starts for our new VM. The next parameter set will be looking at is the one that is named get view. With the view type parameter, which is a required parameter by the way we will indicate which type of internal object. We want to have it return. Note how we use the same select object line together report with the candidate data stores. Internal Vsphere objects can be quite big. And with the optional property parameter, we can limit which property should be returned by the get view commandlet. But watch out when you use this property parameter as you can see in the output on the right side in this case, the name property seems to be missing. Which means that we explicitly have to specify all properties that we want to have available? VSphere environments can be quite big and complex. A typical example is where in geographical locations are each represented by a separate data center. Over the search route parameter. We can limit where they get view commandlet should look for objects in this case. We are using a data center. We're passing a MoRef, which is a managed object reference kind of a pointer to limit the scope of the search as you will notice in the output on the terminal window. We have a smaller set of data storage that has returned. The final and also quite powerful, parameter is the filter parameter. The filter is presented as a hash table. Where the key is the name or the location of the property and the value is a regular expression against? Which we want to compare the value of the property. Note that in the filter we had to convert the Boolean to its string representation that’s because regular expressions expect the string. In the filter hashtable. We can add multiple conditions in this case, we're adding a condition that we only select data store whose name starts with DS? As you can see in the output. We know arrived at a very specific set of candidate data stores. They are located in a specific data center. Their name follows a certain convention that we imposed and they are shareable in the cluster. Thanks for watching.