get - view filtering

The following code returns no resource pool yet I know that there are some

$myhost = get-view viewtype - hostsystem-property name, Parent - filter @{'Name' = 'Blah'}

$resourcepools = get-view - viewtype ResourcePool-property name, filter-owner @{'Owner' = $myhost. Parent}

$resourcepools

I also tried

$myhost = get-view viewtype - hostsystem-property name, Parent - filter @{'Name' = 'Blah'}

$resourcepools = get-view - viewtype ResourcePool-property name, filter-owner @{Owner.Value "= $myhost". ""} Parent.Value}

$resourcepools

Nothing helps.


Anyone know why this is and how to do it?

Kind regards


Ryan

It will work

$resourcepools = get-view -viewtype ResourcePool -property Name, Owner -filter @{"Owner"=$myhost.Parent.Value}

Tags: VMware

Similar Questions

  • PowerCLI: Get - view filters and OR conditions

    Hi all

    I'm little a beginner when it comes to tools from command-line and scripting in general, but I was playing around with PowerCLI and Get - view in particular and I wanted to understand if there was a way to specify multiple conditions and a 'GOLD' between them make in filters.
    Something like...

    Notice-EEG - ViewType VirtualMachine-filter @{name = "ABC123" or snapshot! = "} # does not work

    I took a glance at the documentation and I was unable to find a solution, but maybe a more experienced writer can confirm this?
    Thank you!

    I'm afraid, this is not possible, that all expressions in the filter hash table must comply.

    So, indeed, all expressions are AND-ed together.

    You can make a combination of two Get - sight lines of course.

    But I admit that this solution is not elegant or optimal.

  • Using filters and Get - view to find virtual machines with a specific guest operating system.

    I have the following code snippet to find all virtual machines with the updated OS to ' Red Hat Enterprise Linux * "prompt. It does not work. If the filter is left out, I find myself with all virtual machines.

    The immediate question is the specs for the game ' Red Hat Enterprise Linux. " Originally from the "Performance Difference between GET - VM and GET-VIEW")

    http://www.batchworks.de/performance-difference-between-get-VM-and-get-view/ ).

    $ClusterFilter = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{“Name” = $ClusterName } | select -ExpandProperty MoRef

    $VirtualMachines = Get-View -ViewType VirtualMachine -Property Config -SearchRoot $ClusterFilter


    The biggest problem for me is to understand for Get-View filter. I was capable of a bit of insight to gleen from the URL below, but I think what Miss me is the reference (Microsoft) for what is happening to the right of the equal sign. What is the correct terminology for this type of query expression / where the syntax is 'left' = 'straight' and keywords such as "-match" are not allowed.

    http://purple-screen.com/?Cat=3

    VMware vSphere 5.1

    http://Wannemacher.us/?p=259

    Regular expressions with Windows PowerShell

    Right in the filter expression is an RegEx expression, please allow for characters before and after the word Linux.

    And the name of the OS is Config.GuestFullName.

    I corrected the entries more early as well.

    $ClusterName = "^MyCluster$"$ClusterFilter = get-view -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = $ClusterName } | select -ExpandProperty MoRefWrite-Host $ClusterFilter
    
    $VirtualMachinesNoFilter   = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter $VirtualMachinesWithFilter = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter -Filter @{"Config.GuestFullName"=".*Linux.*"}
    
  • MoRef filtered get - view

    Try to get resutlts an error

    PS > Get-View - ViewType property, Parent, MoRef hostsystem-name

    Get - view: 2011-02-08 08:46:35 Get-View

    Online: 1 character: 14

    + Get-view < < < < ViewType - hostsystem-name of the property, Parent, MoRef

    + CategoryInfo: NotSpecified: (:)) [Get-view], InvalidProperty)

    + FullyQualifiedErrorId: Client20_MoServiceImpl_GetNetInteropEntityView_ViError, VMware.VimAutomation.ViCore.Cmd

    ts.Commands.DotNetInterop.GetVIView

    I can still run and access.

    PS > (Get-View - ViewType hostsystem). MoRef

    Is there a way to specify this property which must be returned?

    Kind regards

    Ryan

    The command

    Get-view ViewType - hostsystem-name of the Parent property

    Returns an array if you have more than one host. This means that you must do something like:

    (Get-view ViewType - hostsystem-name of the Parent property) [0]. MoRef

    or

    $x = get - View - ViewType hostsystem-property name, Parent
    $x [0]. MoRef

    to retrieve the first host MoRef.

  • 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.

  • Regular Get-view filter expressions

    I have the following code:

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = $vms [$i] .name} - property @("Nom", "Config.GuestFullName") | Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

    $vms contains some virtual machines to a folder called 'test '. I have 2 virtual machines in the folder - 'test' and 'test2 '. When I run the code above, when the 'test' VM is put in the loop, she returned twice. Time for 'test', and 'test2 '. I'm looking for a regular expression that I can use to get the exact name of each virtual computer so that only 1 value is returned by $vmOS in each loop.

    The filter is a regular expression, you can use the indicators of positions (^ and $).

    Something like that

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = "^ $($vms[$i].name)$" ""}-property @("Nom","Config.GuestFullName") |

    Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

  • 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 ClusterComputeResource vs StoragePod

    The following example of a loop in the cluster/host/vm to PowerCLI LinkedView - a Simple example, I found. The beautiful Hippo

    $VMArray = @)

    $ClusterArray = get-view ViewType - ClusterComputeResource

    $ClusterArray | % {

    $_. UpdateViewData ("$host.name", "Host.VM.Name")

    $ClusterName = $_. Name

    $_. LinkedView.Host | % {

    $HostName = $_. Name

    $_. LinkedView.VM | % {

    $VMName = $_. Name

    $VMArray += new-Object - TypeName PSObject - Prop)

    @{'Clusters' = $ClusterName;

    "Home" = $HostName;

    'Name' = $VMName

    }

    )

    }

    }

    }

    I tried the equivalent code for the storage of cluster/datastore/vm

    $DSVMArray = @)

    $DSClusterArray = get-view ViewType - StoragePod

    $DSClusterArray | % {

    $_. UpdateViewData ("ChildEntity.Name", "ChildEntity.VM.Name")

    $DSClusterName = $_. Name

    $_. LinkedView.ChildEntity | % {

    $DSName = $_. Name

    $_. LinkedView.VM | % {

    $VMName = $_. Name

    $DSVMArray += new-Object - TypeName PSObject-Prop)

    @{'DSCluster' = $DSClusterName;

    'Datastore' = $DSName;

    "VM" = $VMName;

    }

    )

    }

    }

    }

    But this error

    Exception by calling 'UpdateViewData' with '2' or the arguments: "the path specified."

    is not correct. Item "vM" does not exist. »

    Online: 4 char: 5

    +     $_. UpdateViewData ("ChildEntity.Name", "ChildEntity.VM.Name")

    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)

    + FullyQualifiedErrorId: ArgumentException

    The data structures are the same for me.  Could someone please explain the error?

    Cannot use UpdateViewData if properties can be null.  In my case I have warehouses of data with no VM so I can not UpdateViewData ("ChildEntity.VM.Name").

    $DSVMArray = @)

    $DSClusterArray = get-view ViewType - StoragePod

    $DSClusterArray | % {

    $DSCluster = $_

    $DSCluster.UpdateViewData ("ChildEntity.Name")

    $DSClusterName = $DSCluster.Name

    If ($DSCluster.LinkedView.ChildEntity.VM.Count - gt 0) {}

    $DSCluster.LinkedView.ChildEntity.UpdateViewData ("VM. Name")

    }

    $DSCluster.LinkedView.ChildEntity | %{

    $DSName = $_. Name

    $_. LinkedView.VM | %{

    $VMName = $_. Name

    $DSVMArray += new-Object - TypeName PSObject-Prop)

    @{'DSCluster' = $DSClusterName;

    'Datastore' = $DSName;

    "VM" = $VMName;

    }

    )

    }

    }

    }

  • Get - VM to Get-View - viewtype VirtualMachine

    We want to replace our Get-VM with Get-View-viewtype VirtualMachine function, because it is a faster method.

    But for some reason, the output is not the same.

    You expect that they return both the same VirtualMachine object.

    Out with Get - VM:

    Name, PowerState, NUM CPUs, MemoryGB

    Out with Get-View - viewtype VirtualMachine:

    Capacity, Config, layout, LAyoutEx, storage,... all the VMware.Vim.VirtualMachine object.

    Our methods:

    $Hosts = get-VMsByLocation-site $Location

    $VMs = @)

    $Hosts | {ForEach}

    (A) $VMs += Get - VM $_

    (B) $VMs += Get-view -ViewType VirtualMachine - filter @{'Name' = $_}

    }

    https://www.VMware.com/support/developer/windowstoolkit/wintk40u1/HTML/get-VM.html

    https://communities.VMware.com/thread/474763

    https://www.VMware.com/support/developer/converter-SDK/conv50_apireference/Vim.virtualmachine.html

    https://pubs.VMware.com/vSphere-51/index.jsp#com.VMware.PowerCLI.cmdletref.doc/virtualmachine.html

    Hello, tendonsie-

    Yes, you are right: If you change the type of object that you are using, and then later call what's going used probably not work with .

    However, another part of the power of Get - view: you have direct access to a representation of the object "full" vSphere - the View .NET VirtualMachine object, in this case.  So, you do no need another call to get the CpuReservationMhz - you can get it directly from the object VirtualMachine who have already recovered you.  An example of include these goods in the output (based on the example I gave first):

    Get-View -ViewType VirtualMachine -Property Name,Runtime.PowerState,Config.Hardware,Config.CpuAllocation.Reservation | Select-Object Name,    @{n="PowerState"; e={$_.Runtime.PowerState}},    @{n="NumCPU"; e={$_.Config.Hardware.NumCPU}},    @{n="MemoryGB"; e={$_.Config.Hardware.MemoryMB / 1KB}},    @{n="CpuReservationMhz"; e={$_.Config.CpuAllocation.Reservation}}
    

    You see the additional calculated property, CpuReservationMhz, here.  Now you don't need even have call the Get-VMResourceConfiguration cmdlet.

    Thus, work comes to discover what are the properties of the View .NET object that you have recovered.  And this work is supported by the vSphere API documentation, a link that is available to VMware vSphere Web Services SDK Documentation.  How is that?

  • Get-View issue

    I try to get the specific host name and version number of the guests in a data center. I'm may be far, but here's what I use to date:

    $servers = get-Datacenter "my DataCenter | Get-Vmhost

    foreach ($server in $servers)

    {

    Get-view ViewType - HostSystem-Name, property Config.Product | Select Name, {$_.config.} Product.FullName} | Export-CSV P:\mypath

    }

    The issue I'm having is the for loop runs against the entire vCenter and not the variable so the output is all host names and the version numbers for the vCenter Server?  I checked that the $servers variable includes only hosts in the data center that I intended. What I'm missing here?

    Thank you

    You're doing a general Get-views against whole environment, which will return all the HostSystems.

    But there is indeed no need the loop ForEach and Get-View, you can access this property directly via the ExtensionData property.

    Something like that

    Get-Datacenter "my DataCenter | Get-Vmhost |

    Select Name, @{N = 'Full name'; E={$_. ExtensionData.Config.Product.FullName}} |

    Export CSV P:\mypath\report.csv - NoTypeInformation - UseCulture

  • 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

  • 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}}

    }

    }

  • 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

    }

  • show the parent object of get - view - ViewType HostSystem

    I want to change the code snippet below (http://kb.vmware.com/kb/1012514) to include the parent object.

    Notice-EEG - ViewType HostSystem-Property Name, Config.Product. Select Name, {$_.} Config.Product.FullName}, {$_.} Config.Product.Build} | FT-auto

    When I run the modified version, I get 'ComputeResource-domain-sNNNN' or 'ClusterComputeResource-field-cNNN' in the Parent column. If I make one

    Get-Cluster ClusterComputeResource-field-cNNN

    I get the name of one of our groups. So I tried variations of the following, and I still can't get a good Parent.

    C:\ PowerCLI > notice-EEG - ViewType HostSystem-name of the property, Config.Product, Parent | Select Name, {$_.} Config.Product.FullName}, {$_.} Config. Product.Build}, ($_.) Parent | Get-cluster) | Sort - the name of the property. FT-auto

    Select: cannot convert System.Object [] to one of the following types {System.String, System.Management.Automation.ScriptBlock}.

    At line: 1 char: 72

    + view the GET - ViewType HostSystem-name of the property, Config.Product, Parent | Select Na...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo: InvalidArgument: (:)) [Select-Object], NotSupportedException)

    + FullyQualifiedErrorId: DictionaryKeyUnknownType, Microsoft.PowerShell.Commands.SelectObjectCommand

    PowerCLI C:\ >

    I realize that it does not help that, in some cases Parent will be a cluster object and in other cases it will be an object Folder or Data Center. I also tried

    .... $( if ( $_. Parent) {get-cluster-id $_.} Parent})

    .... ( if ( $_. Parent) {get-cluster-id $_.} Parent})

    .... (get-cluster-name ($_.)) Parent). Name)

    .... (get-cluster-name [string]($_.)) Parent). Name)

    (1) if I'm only looking on with parents of cluster hosts, is there a way to ignore all others?

    (2) how can I get the name of the parent cluster?

    Try like this

    Get-view ViewType - HostSystem-name of the property, Config.Product, Parent |

    Select Name,

    @{N = ' product'; E={$_. Config.Product.FullName}},

    @{N = 'Build'; E={$_. Config.Product.Build}},

    @{N = "Cluster"; E = {}

    $parent = get-view-Id $_. Parent - the Parent property name

    While ($parent - isnot [VMware.Vim.ClusterComputeResource] - and $parent. Parent) {}

    $parent is get-view-Id $parent. Parent - the Parent property name

    }

    If ($parent - is [VMware.Vim.ClusterComputeResource]) {}

    $parent. Name}}} |

    Format-Table-auto

  • 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]}

Maybe you are looking for