Speed by using Get - VM vs Get-View

Many VI Toolkit script I wrote end up needing to do something like this:

Get-VM-name "vmname" | Get-View | etc.

For some reason, I have to repeatedly Get-display to get something of value in the script.   For anyone who is located in a large enough knows that it's quite slow.   My colleague will me and said ' why don't you just jump the Get - VM and use Get - view directly?   You know it's a pretty clever idea, so I do.   I'm blown away at how much difference it is so I'll and the script I use time.

Using the command Get-VM-name "vmname" | Get-view takes 1 minute and 37 seconds to run.  Ugh.

Using the command Get-View - ViewType VirtualMachine-filter @{"Name" = "vmname"} takes... Wait what he

Wait what he

Wait what he

5.12 seconds!

Yes.  I don't do this.  The question I have for the VI Toolkit/Powershell assistants out there is WHY! ???

The script I used for the test is attached.  Yes, it's not the world the better as its only my 3rd custom wrote the script to this day well I'll take recommendations contained in private messages or something different to make it better, nicer, faster, cooler, more powershell as.

Hey, Ian,

You can verify that you are using VI Toolkit 1.0 Update 1 (v.1.0.1). Between 1.0 and 1.0 1 update we have taken measures to improve the speed of Get - VM (limited). So if you're on upgrade-1.0.0 to 1.0.1 will relieve your problem a little bit.

Basically, the reason why "Get - VM" is significantly slower than 'Get-View - ViewType VirtualMachine' is the virtual computer object is quite large and contains much more data than the view.

A slow Get - VM is clearly a serious problem because it is by far the most frequently invoked cmdlet. If we look at ways to resolve the problem.

One of the biggest steps we are taking is delegating the filtering on the server nickname. So, when you call Get - VM "vmname" the server would send a single virtual machine. This optimization is based on a feature which is new to VC 4.0. The bad news is that it will be a while before out us the version that has this optimization.

Meanwhile, we are looking at ways to reduce the size of the VirtualMachine object by removing some of these objects nested such as VMGuest and virtual devices. The largest obstace of this change is the need for backward compatibility. If it's not completely simple, but I think that we will be able to find a compromise accepbable.

Tags: VMware

Similar Questions

  • How to read the VM ProvisionedSpaceGB and UsedSpaceGB using get - view?

    Hello

    I would like to retrieve the properties of the VM ProvisionedSpaceGB and UsedSpaceGB using get - view and not get - vm.

    How do I do that?

    Thank you very much in advance!

    Kind regards

    André

    Hello, Andre-

    You can retrieve some properties of an object view VirtualMachine and then do some computed properties, such as:

    ## get the View object of this VM, with a choice few properties (faster), then select some info about the objectGet-View -ViewType VirtualMachine -Filter @{"Name" = "^myVM0$"} -Property Name,Summary.Storage |    Select Name,        @{n="ProvisionedSpaceGB"; e={($_.Summary.Storage.Committed + $_.Summary.Storage.Uncommitted) / 1GB}},        @{n="UsedSpaceGB"; e={$_.Summary.Storage.Committed / 1GB}}
    

    To just get these some properties in the call to Get-view is the smaller memory usage in the PowerShell session and much higher speed during the extraction of the View object (without specifying properties to retrieve, the cmdlet returns all properties). How does do for you?

  • Using Get - view instead of Get - VM for BusSharingMode from a virtual computer

    Yet again, another issue was with Get - view. I searched a lot of documentation, but still I don't get the logic how to find good properties that I need to use.

    In this case, I need to transfer this one:

    Get - VM | Get-SCSI controller. Where-Object {$_.} BusSharingMode - eq ˜Physical"} | Select {$_.} Parent.Name}, BusSharingMode

    in:

    Notice-EEG - ViewType VirtualMachine-Property Name,Config.NameofthePropertyforBusSharingMode

    I will be grateful if someone could provide a documentation (or at least give me an idea what to read to get oriented) on these properties and their format so that they can be used to Get-View.

    The closest thing I found is this one: http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.VirtualMachine.html and the VirtualMachineConfigInfo: http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigInfo.htmlhttp://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigInfo.html
    I guess that in this case, we are talking about VirtualHardware (SCSI controller): http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.VirtualHardware.html and still I cannot establish the connection.

    It is all documented in the VMware vSphere QAnywhere, but as the title suggests, this is a reference.

    The vSphere Web Services SDK Programming Guide is intendedas a learning guide.

    Only no VMware book that explains a bit more on the vSphere API and objects is the book of Steve Jin, called VMware VI and vSphere SDK: management of VMware Infrastructure and vSphere

    It is written for Java developers, but it explains the basic concepts.

    In this specific question, you must know that all devices connected to a virtual computer is located in Config.Hardware.Device.

    It is a loop through the devices and extract the virtual SCSI controllers, also with bus physics active sharing.

    Once you have, it's simple extract properties.

    foreach ($vm in Get-View - ViewType VirtualMachine - Name property, Config.Hardware.Device) {}

    $scsi = $vm. Config.Hardware.Device | where {$_-is [VMware.Vim.VirtualSCSIController] - and $_.} SharedBus - eq "physicalSharing"}

    {if ($SCSI)}

    $scsi | Select @{N = "VM"; E = {$vm. Name}},

    @{N = "Controller"; E={$_. DeviceInfo.Label}},

    @{N = "BusSharingMode"; E={$_. SharedBus}}

    }

    }

  • Use get - view to get the host data center

    Hey guys,.

    I'm trying to shoot the host number of name and the version with get-view.

    I got to that, but I also want to get the data center that host belongs to.

    How can I get that advice please, don't have Googling has not helped a lot.

    Thank you

    RJ

    With the ExtensionData property we have access to the object VirtualMachine .

    Most of the managed objects vSphere has a property, called Parent, which points to the object that is connected to our object (the ' mother' in other words).

    The content of the Parent property is a MoRef (pointer). To get the real object, we use the cmdlet Get-view with this MoRef.

    We repeat this process in a while loop until the parent object is an object of data center .

    It's a bit like the structure of the tree in the vSphere Client.

    You start with the ESX (i) server and back up in the tree until you encounter a data center.

  • Get VM network information using Get-view

    Hello

    I made a simple script which is "dump" of information network VMS as below.

    "

    Name of the virtual machine

    1; 1 network card; Network name; MAC address, IP address.

    2; NIC 2; Network name; MAC address, IP address.

    "

    I used below variable.

    $_. Config.Hardware.Device (NIC 1),

    $_.Guest.Net.Network (network name).

    $_.Guest.Net.MacAddress (MAC address).

    $_.Guest.Net.IpAddress (IP address).

    Everything works fine, but not for the virtual machines that use distributed vSwitch. For these virtual machines, the name of the network ($_.Guest.Net.Network) is empty. I do something wrong or should I get another var network name?

    I just double checked a test machine in my lab.

    There are two different connections of portgroup DVS, here is the result of one who has, on the network, called "VM Network", which is our network "prod" in the laboratory:

    PowerCLI C:\ > $vm. Boulevard [1]. IpConfig.IpAddress

    IP address: 2607:f190:1:0:449 c: d037:99cf:e180

    LG: 64

    Origin: perturb

    Status: unknown

    Life expectancy:

    DynamicType:

    DynamicProperty:

    IP address: fe80::449c:d037:99cf:e180

    LG: 64

    Origin: perturb

    Status: unknown

    Life expectancy:

    DynamicType:

    DynamicProperty:

    IP address: 10.10.100.16

    LG: 24

    Origin: manual

    State: preferred

    Life expectancy:

    DynamicType:

    DynamicProperty:

  • The use of Get - view instead of Get - VM for the advanced settings of a virtual computer

    I have a question in relation to the advanced settings of a virtual machine and using Get - view instead of Get - VM for this particular case:

    Get - VM * | Get-AdvancedSetting - name "scsi * sharing | Select the entity, Name, Value

    My idea is to use:

    Notice-EEG - ViewType VirtualMachine. Where {-not $_.} Config.Template} | Where {$_.} {Advanced.Setting - eq ' scsi * sharing "} | Select the entity, Name, Value

    but as far as I can see there is nothing for the advanced configuration of 'VirtualMachine' here: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FVirtualMachine.htm

    I also took a quick glance at https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.ConfigSpec.html , but I can't figure out how to use "extraConfig"in the script PowerCLI to extract this particular information for "Sharing of SCSI".»

    There is information how to use the API to add or change a computer virtual here .vmx file key advances: http://blogs.vmware.com/PowerCLI/2008/09/changing-vmx-fi.html but it is not clear to me how to use it just to extract information without changing what.

    Try like this

    foreach ($vm in (Get-View - ViewType VirtualMachine - property Name, Config.ExtraConfig - filter @{'Config.Template ' =' False'})) {}

    $vm. Config.ExtraConfig | where {$_.} Key - like "{scsi * sharing '} |"

    Select @{N = "VM"; E = {$vm. Name}},@{N='Template'; E = {$vm. Config.Template}}, Key, Value

    }

  • Get-View for VMS in subfolders

    Hello community

    I need the list of all the virtual machines in a specific folder, including subfolders.

    In fact, I use the following script

    $vms = Get-Folder "VDI" | Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"}
    
    foreach($line in ($vms | Get-Random -Count 20) ) { 
        if($line.PowerState -eq "PoweredOff") {
            $line | Start-VM -RunAsync | Out-Null
        }
    }
    

    The script runs periodically, and it will take more than 30 seconds to over 2000 virtual machines I want to speed up with Get - view. I've already tried it, but unfortunately it does not list the virtual machines of the subfolders.

    Someone at - it an idea how to solve this problem?

    You can try like this

    $folderName = "VDI".

    $folder = get-View - ViewType property file-name - filter @{'Name' = $folderName} | Select MoRef - ExpandProperty

    Notice-EEG - ViewType VirtualMachine - SearchRoot $folder |

    Select name

  • Get-View and - filter

    I'm a (relatively) new convert to get - view the incredible increase in speed to run scripts PowerCLI through ESXi hosts hundreds / thousands of virtual machines.

    I've been struggling with how to do it with a list of the MV?  What I want to do, it's with a provided list of VMs get the hardware version and version of the tools.

    Normally, if you wanted a report of everything that you would do the following:

    Notice-EEG - viewtype VirtualMachine-property name, Config. Select Name, @{N = "HWVersion"; E={$_. Config.Version}},@{N="Tools '; E={$_. Config.Tools.ToolsVersion}} | FT-auto

    Now read on - filter is seems the way to go-, but it uses a hash table.  That is to say "Name" = "Foo".  It does not seem to manage 'Name' = $vmList where $vmList is a collection of multiple virtual machines.  I will not go into how if the variable is a unique virtual machine that Foo matches Foo and FooBar.

    What I have used is the following:

    $vmList = get-content c:\scripts\import\listofvms.txt

    Get - vm $vmList | Opinion-GET-property name, Config. Select Name, @{N = "HWVersion"; E={$_. Config.Version}},@{N="Tools '; E=$_. Config.Tools.ToolsVersion}} | FT-auto

    The only problem is that I feel like this is a workaround solution - it should all be achievable using get - view directly.  -If I wanted to use - filter, with a collection of virtual machines would how I did this?

    See you soon

    Robert

    Hi Robert,.

    If you use the cmdlet Get-view and search two VM called foo and bar, you will need to make a filter with a regular expression. You must use the vertical bar as a sign "or" in the regular expression. For example

    Notice-EEG - ViewType VirtualMachine-Property Name, filter-Config @{"Name"=' foo | "} bar'}

    You can use the .NET Join method string to construct the regular expression from the $vmList variable. Like this:

    $vmList = get-content c:\scripts\import\listofvms.txt
    Get-View -ViewType VirtualMachine -Property Name,Config -Filter @{"Name"="$([string]::Join('|',$vmList))"} | `
    Select-Object -Property Name,@{N="HWVersion";E={$_.Config.Version}},@{N="Tools";E={$_.Config.Tools.ToolsVersion}} | `
    Format-Table -AutoSize
    

    Best regards, Robert

    Post edited by: RvdNieuwendijk has added the explanation at the beginning of the post.

  • Update custom fields in VC without using Get - VM

    Greetings-

    I am trying to determine a way to update a custom field in Virtual Center via powershell without using Get - VM.  I am able to extract custom using Get-View fields

    $VMView = Get-View -ViewType virtualmachine -filter @{"Name" = $input_machinename}

    return $VMview.customvalue [7] .value

    However, all of the examples I found related to the update/filling of custom fields requires the use of Get - VM.  While that's great and all, but everyone knows at this stage that Get - VM is something you want to avoid problems with speed

    http://communities.VMware.com/thread/206909;JSESSIONID=C3AC43115524E4F5F8608530367321B3?TSTART=0

    http://communities.VMware.com/message/1122166#1122166

    It is an example of the code snippet that I fight with in an attempt to update a custom field.

    #This is the line which takes about 2 minutes

    $VMName = Get-VM | {$_.name - eq "adv0010vpvc01"}

    $VMView = $VMName | Get-View

    $VMName.CustomFields.values [3] # prints the name of custom field

    $VMName.CustomFields.keys [3] # print the value of custom field

    $VMView.setCustomValue($VMName.CustomFields.keys[3],"10/10/2000") #Updates custom the field with the value "10/10/2000.

    Thank you very much

    The final alternative is to use the SDK method to set a custom field.

    Can you try this and see if it is faster?

    $input_machinename = 
    $CustomVarName = 
    $CustomVarValue = 
    
    $vm = Get-View -ViewType virtualmachine -Filter @{"Name"=$input_machinename}
    $vm.setCustomValue($CustomVarName, $CustomVarValue)
    
  • Get-view SearchRoot when duplicate. MoRef exists

    I created a script to list the details of the bunch and I thought I would faster by using get - view instead of the Get command for each object.  I came across a problem on line 14.  It seems that I have data centers in different virtual centers with the same. MoRef values.  Not sure how I can script around that.

    Note that this script below is a global script version

    $csvreport = @()
    $ClusterList=@()
    $OutputFile="C:\Temp\looptesting.csv"
    $Date=Get-Date -Format d
    
    
    
    
      foreach ($virtualcenter in $DefaultVIServers) {
    
    
      ForEach ($DC in (Get-View -ViewType  Datacenter -Server $virtualcenter)){
    
      Foreach ($cluster in (Get-View -ViewType ClusterComputeResource -SearchRoot $DC.MoRef)){
    
      $ClusterList = "" |select-object "Collection Date","Virtual Center",DataCenter,Cluster
    
      $ClusterList."Collection Date"=$Date
      $ClusterList."Virtual Center"=$virtualcenter
      $ClusterList.DataCenter=$DC.Name
      $ClusterList.Cluster=$cluster.Name
    
      $csvreport += $ClusterList 
      }
      }
      }
    
    
    
    
    $csvreport |export-csv -NoTypeinformation $OutputFile
    

    Can't you just use the Server parameter on line 14, as you did on line 12?

  • Get-view Config.Hardwar.Device network adapter key 4000 solve Type of device?

    I know Get-NetworkAdapter before someone proposes.

    Now when using Get-view I drill down on a single record to the NIC see example in the attached picture.

    I know that the device type is an e1000e I see not listed in the hardware configuration, so I'm sure that his code in a hash table.


    My best guess is that 4000 KEY = E1000E but I would like a complete list of all the buttons on the unit so that I can solve them in my scripts.

    Any help is welcome and appreciated thank you.

    The type of NETWORK adapter is the objecttype.

    The following will first list all the types of devices and then filter the E1000 map

    $vm = get-View - ViewType VirtualMachine-filter @{'name '=' MyVM'}

    $vm. Config.Hardware.Device | %{$_. GetType()}

    $vm. Config.Hardware.Device | Where {$_-is [VMware.Vim.VirtualE1000]}

  • Getting the data center of VirtualMachine with Get-View information

    Hello

    Y at - it a faster way to get the name of data using Get-View and the viewtype VirtualMachine Center.

    I found the following:

    Get-View -ViewType VirtualMachine -filter @{ "name" = "mtl1fsit02" } | Select-Object -Property Name,

    @{ Label = "GuestOSName"; Expression = { $_.summary.guest.guestfullname } },

    @{ Label = "Datacenter"; Expression = { (Get-view (Get-View (Get-view $_.parent).parent).Parent).name } }

    Thank you guys

    I think that the property calculated for the data center does not work in all situations.

    It assumes that your virtual machines are 3 levels down from the data center, which is not always the case.

    I personally use a loop, passing up through the parents, until he finds an object data center.

    something like that

    @{N = 'Center'; E = {}

    $parentObj = get-view $_. Parent

    While ($parentObj - isnot [VMware.Vim.Datacenter]({))

    $parentObj = get-view $parentObj.Parent

    }

    $parentObj.Name

    }

  • Filtering problem by vm properties obtained using get-display, instead of get - vm

    Hello world.  I have a script which allows to obtain a certain number of properties different vm through get - view.  I would get out the information in different html pages, but encounter problems of filtering.

    for example, I have the powerstate for vm I can view by typing $vm.runtime.powerstate, and I would like to filter by only of the virtual machine that are turned on.  In the previous scripts, I used where {$_.} PowerState - 'Receiving' eq} to list only power on vm.  This doesn't seem to work, and I think that its because previously I got information using get - vm, not get - see.

    How can I filter the information that I have so that it shows only powered on vm? using get - vm I could use the following...

    $PRDVMTools = $DatacenterTmp | where {$_.} PowerState - eq "Receptor" - and $_. ToolsStatus - don't "toolsOk" - and $_. ToolsStatus - don't "toolsOld"} | Tri-objet

    ToolsVersion

    $PRDVMTools | ConvertTo-html-property VMName, OS, ToolsStatus, ToolsVersion. Out-file - add $htmlPRDVMTools

    I can't work out how to do it using the properties returned by using get - view instead of get - vm

    any help would be appreciated more

    Thank you

    I checked the script more in detail and I found two things that I don't understand:

    1. you seem to be an iteration through data centers, hosts, and virtual machines. Why recover you clusters?

    2. Why do you have so many properties of the virtual machine in the $row variable, if you save only 6 of them in the HTML file?

    I enclose the updated the script I did according to my understanding of what you are trying to do. You can optimize it more if you specify the properties of the specific vm you want to recover with the parameter of Get - view property on line 34.

  • Problem combining Get - VM and Get-View

    I worked on a script for a while, and very close if he's working as I want.  The script below is what I have so far and works as I want.

    $(foreach ($cluster get-cluster) {get - view - viewtype VirtualMachine - SearchRoot $cluster.id | select @{N = 'The virtual computer name';}) E={$_. Name}}, @{N = "PowerState"; E={$_. Summary.Runtime.PowerState}}, @{N = "guest operating system"; E={$_. Config.GuestFullName}}, @{N = 'Cluster'; E = {$cluster. Name}}, @{N = 'Notes'; E={$_. Summary.Config.Annotation}}})

    However, I can't seem to shoot our custom annotations by using Get - view but can't Get - VM.  The script below works.

    Get - VM | Select Name, @{N = "Org1.Environment"; E = {(Get-Annotation-entité $_-CustomAttribute "Org1.Environment").} Value}}

    How to combine the two?  Any help would be greatly appreciated.

    Hello, Grimdari-

    You are pretty close to.  A couple of ways you could do this, the first using the code of Get-Annotation you did already:

    foreach ($cluster in Get-Cluster) {    Get-View -ViewType VirtualMachine -SearchRoot $cluster.id | Select @{n="VM name"; e={$_.Name}},        @{n="PowerState"; e={$_.Summary.Runtime.PowerState}},        @{n="Guest OS"; e={$_.Config.GuestFullName}},        @{n="Cluster"; e={$cluster.name}},        @{n="Notes"; e={$_.Summary.Config.Annotation}},        ## using the Get-VIObjectByVIView cmdlet; slower        @{n="Org1.Environment"; e={(Get-Annotation -Entity (Get-VIObjectByVIView $_) -CustomAttribute "Org1.Environment").Value}}} ## end foreach
    

    And the second, stick with the info you've already recovered in the call to Get-View :

    ## selected properties to retrieve in Get-View call$arrViewPropertiesToGet = "Name","Summary.Runtime.PowerState","Config.GuestFullName","Summary.Config.Annotation","CustomValue","AvailableField"foreach ($cluster in Get-Cluster) {    Get-View -ViewType VirtualMachine -Property $arrViewPropertiesToGet -SearchRoot $cluster.id | Select @{n="VM name"; e={$_.Name}},        @{n="PowerState"; e={$_.Summary.Runtime.PowerState}},        @{n="Guest OS"; e={$_.Config.GuestFullName}},        @{n="Cluster"; e={$cluster.name}},        @{n="Notes"; e={$_.Summary.Config.Annotation}},        ## just using the data already retrieved; far faster        @{n="Org1.Environment"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Org1.Environment"}).Key}).Value}}} ## end foreach
    

    The second way is much faster, though it might be a little less obvious how she came up with the results.  He becomes the value of CustomValue where CustomValue key corresponds to the key AvailableField for the AvailableField with the name of the attribute you want.  Anyway, how those who do for you?

  • Folder is a virtual computer in the use of Get-View

    All, I run a script to collect information on the virtual machines in the environment, but have not been able to figure out how to get the file to in the virtual machine is.  I know I could use a get - vm | Select name, file etc. but at the time wherever I have add a get - vm statement, I'll add a TON of execution time of the script.

    I currently use it as my get-views command...

    Notice-EEG - ViewType VirtualMachine-Name property, Runtime.Host, Config.GuestFullName, Config.Annotation, Config.Hardware.NumCPU, Config.Hardware.MemoryMB, Guest.Disk, Config.Template, Guest.IpAddress | Sort-Object-property name. %{
    If ($_.) Config.Template - not $true) {}
    $row = "" | Select-Object Name, Notes, MemoryGB, host, CPU, OS, Cluster, IPAddress, DiskSpaceGB, UsedSpaceGB

    ....

    I know I'm just grabbing some properties, but I was not able to find the property that gives the name of the folder.

    To try to find the right one, I did

    $vm = get-View - ViewType VirtualMachine-filter @{"Name" ="VM_Name"}

    Then just walk through the $vm variable. (Property) etc.

    Anyone?

    In the VirtualMachine object, the Parent property contains the MoRef (pointer) to the object of the file.

    In order to

    Select Name,@{N="Folder; E = {Get-view $_.} Parent | Select name - ExpandProperty}}

Maybe you are looking for

  • How to import HP laptop again Pandora stations Samsung phone?

    How to import HP laptop again Pandora stations Samsung phone?

  • How do I create new folders

    I recently bought a 2 GB Fuze for one purpose, to listen to radio podcast. I could not find a way to add folders under the folder "Podcast". For example, I want a folder titled 'Len' in the Podcast folder, but it does not add a new folder.  What Miss

  • Error message every time I try to update Java

    Original title: Java get error message every time I try to dlerror message 1606 every time that I try to put up-to-date Java

  • I have a slow Internet connection under Windows 7.

    My son has a new computer and I bought a wireless adapter, but we have problems with the connection. My two sons have computers identical but different adapters. We're working correctly the other seems slower than dial-up! Original title: Internet co

  • error in node.js

    I've updated my creative cloud yesterday and now I get another error of node. In 2015, it was node.exe error and the work around to replace the node.exe file. Now, it is a mistake to node.js and this is a mistake with Adobe's server-side. This is get