Home > Blogs > VMware PowerCLI Blog


Get-View Part 2: Views and Extension Data

In Get-View Part 1: Introduction I introduced the advanced feature Get-View and a little bit about what it does. Before getting into the views and extension data topic I wanted to add a few thoughts as a segway into this post.

What is Get-View?

If I wasn’t very clear in the first post, Get-View is a method that allows PowerCLI users to return more information in a much faster way. The information returned is not formatted nicely like that of normal PowerCLI cmdlets like Get-VM, however like I said previously, this is a more advanced topic and allows access to more data than the average Joe may require. Using Get-View allows users the ability to work with the underlying API which can bring back many settings and property values from your virtual environment.

Why use get-view?

Similar to the previous paragraph, Get-View allows for faster retrieval of information, as well as information that is otherwise invisible to the user when running other PowerCLI cmdlets. Between its increased speed of data retrieval and the breadth of information available at the users fingertips, it becomes very useful when running reports or other queries on your virtual environment.

What ViewTypes can I use?

When using the get-view cmdlet like we did in the previous post, I used the command:

$VM = get-view –viewtype VirtualMachine –filter @{“Name”=”SDDC-VCAC-IAAS”}

This specified that I was looking for a virtual machine and filtered by the VM’s name. But what are all the ViewTypes I can choose from? Here they are:

    • ComputeResource – Cluster view
    • Datacenter – Datacenter view
    • Datastore – Datastore view
  • DistributedVirtualSwitch –vDS view
  • Folder – Folder view
  • HostSystem – ESX Host view
  • Network – Virtual network view
  • ResourcePool – Resource Pool view
  • VirtualMachine – Virtual Machine view

Now that you know what the options are for ViewTypes, you can give them a shot. To return all objects of an object type simply enter:

get-view –viewtype <your choice of view object> and hit enter. You can always filter the results like we did for the VM above.

Are there any shortcuts?

Well, I’m glad you asked, because as it turns out, if you know what you are looking for and where it is located within the VIObject, there is a cheat that you can use to get information visibile in get-view, without using the get-view command. This is known as ExtensionData. ExtensionData was released back in the 4.x days of PowerCLI that allows you to access the VIObject properties without using get-view. let me show you how this works.

If we save our command as a variable, we can then refer back to it and dig into the object properties:

$VM1 = get-view –viewtype VirtualMachine –filter @{“Name”=”SDDC-VCAC-IAAS”}  *Note that the filter hashtable works for any property of the object, not just the name

Screenshot 2015-02-11 13.57.31

We can then reference the variable and see all of the properties of that object.

Screenshot 2015-02-11 13.57.38

We can navigate deeper into these properties until we wind up at the desired property and value, as seen below:

$VM1.Summary.Config.VmPathName to show us where our VMX file is.

Screenshot 2015-02-11 13.58.49

Now that we’ve done it the longer way using Get-View, lets do the same thing using extension data.

$VM = Get-VM “SDDC-VCAC-IAAS” (we are referencing the exact same VM as in the example above)

When we call $VM you’ll notice it looks different than when we called $VM1. That’s because we used the get-VM cmdlet this time and it formatted the data and only returned a subset of what is actually there.

Screenshot 2015-02-11 13.58.26

Now let’s add “ExtensionData” to our object and see what happens:

$VM.ExtensionData.Summary.Config

Screenshot 2015-02-11 13.59.01

We see the EXACT same information as we did in the first example solely by using the .ExtensionData.<desired location> on our VM object.

Screenshot 2015-02-11 13.59.18Screenshot 2015-02-11 13.59.25

We can utilize this same functionality across the rest of the objects in our virtual infrastructure, allowing us to be even more specific in our reporting, logic and scripts that we run.

Performing Actions

Now that we’ve shown how you can search through and find advanced data leveraging get-view, we should talk about how you can perform actions for the specific objects while using get-view. You may notice that the cmdlets that work with get-vm do not work with get-view. That is because those cmdlets are made to work against a VIObject and when we pull back information with get-view, this data is not formatted into a VIObject, rather it’s part of a view object. This means you will receive an error when trying to use additional cmdlets with your view object.

Screenshot 2015-02-17 09.36.36

We have two solutions:

    1. The first (and easiest because it allows us to work with what has been so common for us) is to use the ‘Get-VIObjectByVIView‘ cmdlet, which will then convert the view object to a VIObject usable by the rest of the PowerCLI cmdlets.

$vcsa = get-view -ViewType VirtualMachine -Filter @{“name”=”vCSA6”}

$vcsa | Get-VIObjectByVIView | Start-VM

Screenshot 2015-02-17 09.33.24

 

  1. The second (which isn’t hard, it’s just not something most people have used) are the view methods. These can be found when using ‘get-view | get-member’:Screenshot 2015-02-17 09.25.01

    This shows us a list of tasks that we can perform on this view object. Once you know what these tasks and methods are, it is very simple to use them as you can see below:

    $vcsa = get-view -ViewType VirtualMachine -Filter @{“name”=”vCSA6”}

    $vcsa.SuspendVM_Task()

    Screenshot 2015-02-17 09.27.23

Summary

To summarize, as you become more familiar with get-view you’ll learn there are some tricks and shortcuts to getting at the raw data you may need for the scripts or reports you are running. Knowing what ViewTypes are available and how to use ExtensionData will allow you to achieve cleaner, shorter, and more concise code.

Stay tuned for the final post on this get-view series (Part 3: Performance Impact)

This entry was posted in Advanced, Customization, Performance, Reporting and tagged , , , , on by .
Brian Graf

About Brian Graf

Brian Graf is a Senior Product Manager - Distributed Resource Management (DRS/HA/DPM) at VMware. Previous to Product Management, Brian worked as a Senior Technical Marketing Manager at VMware, focused on PowerCLI Automation and ESXi Lifecycle technologies. Previous roles also include: Consultant for EMC Consulting. His main focus was Data center migration methodologies and implementations. His background previous to VMware includes Operations Engineering, Virtualization, Business Intelligence, and Exchange/Blackberry Engineering. Get notification of new blog postings and more by following Brian on Twitter: @vBrianGraf

14 thoughts on “Get-View Part 2: Views and Extension Data

    1. Brian GrafBrian Graf Post author

      Good question. It’s in draft form waiting to be posted. vSphere 6 launch pushed it back a little. hope to have it out in the near future.

      Reply
  1. Pingback: Get-View Part 3: Peformance Impact - Is it really THAT much different? | VMware PowerCLI Blog - VMware Blogs

  2. Bouke Groenescheij

    Good article!
    But please be aware of the filter option is based on REGEX. Looking at:
    $vcsa = get-view -ViewType VirtualMachine -Filter @{“name”=”vCSA6″}
    This would possibly grab all VMs with the string ‘vCSA6’ in it (if you would have vCSA61, avCSA6whatever, etc.), and since they share common methods, they all trigger.

    To prevent this, use the exact word in REGEX, adding ^ and $ like:
    $vcsa = get-view -ViewType VirtualMachine -Filter @{“name”=”^vCSA6$″}

    Also, take the property option into account – this will provide a huge performance boost (and lower impact on your vCenter server). If you only need some of the many properties, just pick them:
    $vcsa = get-view -ViewType VirtualMachine -Property “Name” -Filter @{“name”=”^vCSA6$″}

    Cheers, keep them comming!

    Reply
  3. Achim

    How can i use the filter option with a variable?

    @{“name”=”^vCSA6$″}

    $vm=’vCSA6′
    @{“name”=”^($VM)$″} doesn’t work

    Reply
    1. Bouke Groenescheij


      @{“name” = ”^vCSA6$″}
      $vm = "vCSA6"

      Use either:

      @{"Name" = "^$($vm)$"}

      or change your variable to something to include the RegEx like:

      $vm="^$($vm)$"

      From what I can see is you’re trying to put this in a foreach loop? Don’t! Each loop will do an API call, just combine multiple strings first, and use that in you filter.

      Check this code:

      $allvms = "vma","vmb","vmc"
      $filter = $null
      $allvms| % { $filter = "$($filter)^$($_)$|" }
      $filter = $filter -replace ".$"
      $allvmsview = Get-View -ViewType "VirtualMachine" -Filter @{"Name" = $filter}

      Then loop through the results. Advantage: 1 API call ;-). Very fast and low on resource usage.

      Reply
  4. Jimmy

    where’s the example for multiple filters?

    for example:

    Get-View -ViewType virtualmachine -Filter @{“Snapshot”=”VMware.Vim.VirtualMachineSnapshotInfo”;”Config.Template”=”False”}

    does not work properly. How do I format it correctly so both filter pairs work?

    Reply
  5. Pingback: Get-View Part 3: Performance Impact – Is it really THAT much different? » Brian Graf's Virtualization Blog

  6. Amol Patil

    hello,
    Nice update to know the Get-View types.
    I tested this and below is the output of multiple types.
    ——————————————-
    # Get Start Time
    $startVMCheck = (Get-Date)

    $VMviews = Get-View -ViewType “VirtualMachine”
    $Hostviews = Get-View -ViewType “HostSystem”
    $DSViews = Get-View -ViewType “Datastore”
    $DCViews = Get-View -ViewType “Datacenter”
    $VMNetViews = Get-View -ViewType “Network”

    “VM – ” + $vmviews.count
    “Hosts – ” + $Hostviews.count
    “Datastores – ” + $DSViews.count
    “DataCenters – ” + $DCViews.count
    “VMNets – ” + $VMNetViews.count

    # Get End Time
    $endVMCheck = (Get-Date)
    $elapsedTime = $EndVMCheck-$StartVMCheck
    $elapsedTimeOut =[Math]::Round(($elapsedTime.TotalMinutes),2)
    Write-Host “Elapsed Time :> $elapsedTimeOut Minutes ”
    ———————————————————-
    Output is below
    ————————————-
    VM – 1020
    Hosts – 182
    Datastores – 284
    DataCenters – 1
    VMNets – 55

    Elapsed Time :> 14.49 Minutes

    Reply
  7. VCAP6-DTM

    VMware Certified Advanced Professional 6 (Desktop and Mobility Deployment) – The industry-recognized VCAP6-DTM Deploy certification validates that you know how to deploy and optimize VMware Horizon 6 (with View) environments. It proves that you have the knowledge and skills essential to leverage best practices to provide a scalable and dependable Business Mobility platform for your company. Some of the subjects involve: Configuring and managing Horizon View components, configuring cloud pod archituecture, configuring Group Policy settings related to Horizon View, Configuring and optimizing desktop images for Horizon View & Mirage, Configuring and managing App Volumes AppStacks, Configuring desktop pools, Configuring and deploying ThinApp packaged applications, Configuring VMWare Identity Manager, etc.Sebastian’s take on the VCAP6 examination: “In my point of view VCAP6 examination is much better experience as compared with VCAP5, the new examination looks exactly like VMware HOL. The user interface is not difficult, questions are set up on the right area of the screen, and can be concealed to the side or even restored when wanted. My bits of advice to the questions windowpane: if you wish to make it floating, you should know how to restore it back. I ended up moving it all around because I fail to remember how to recover it back. The two arrows that looks like control buttons on the top were created to dock the window to right of left. Fonts could be resized, which i think was better than scrolling down and up the question. The reaction speed of the entire user interface was so a lot faster in comparison with VCAP5.5, and there was no lagging period experienced when transitioning from window to window. Something to keep in mind: BACKSPACE key is not working! I think it is beneficial since you don’t reload your exam window in error, nonetheless, it could be frustrating occasionally when you type some thing mistakenly and you need to select and press Del to remove. The Desktop and shortcuts were arranged very effectively, and all required programs like web browser or Mirage console can be launched. You will find there’s excellent user interface for Remote Desktop Manager and you’ll discover all important RDP connection to servers or desktops with no need to type account information. The web browser had all the links in the Favorite Bar. At the time I’m writing this, there is no extra Thirty minute extension for Non-Native English speaker at No-Native English country, which is actually a bummer. You will find thirty-nine question to respond within the 3 hours time, and this can be actually quite hard for non-native English speakers just like me. Quite a few questions take time to complete, making it safer to neglect the questions that you cannot respond to, and complete those you are able to. At the end of the thirty-nine questions, you could come back to the uncompleted questions in case you still have time. DO not waste a long time on one single question! The examination blue print can be obtained on my blog site at Szumigalski.com. It is well-organized and following it for the examination preparation will assist a great deal. Surely, the most effective is if you could have a lot of hands on experience! I’m in fact very pleased with the exam experience, despite the fact that I passed this time by tiny margin, however i understand what I missed for the exam, find out from the errors and practice harder to acquaint myself with the environment. This accreditation could open up your job prospects!”

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*