Folder Get view filter VM


Hello


I have a script that get all the VM name and IP address on a specific vCenter and the VM naming convention, and it works like a charm. I would go more deep in the filter setting to be able to search in one specific folder.


Is it possible to do with get-view?


Here is my current get-view function:


Notice-EEG - ViewType VirtualMachine-name of the property, Guest.HostName, Config.Hardware.Device, Guest.IPAddress - filter @{"Runtime.PowerState" ="PoweredOn"; "' the name '=' ^ BGSOFW ';


Thanks for your help


Manu

Try something like this

$folderName = "MyFolder"$tgtFolder = Get-Folder -Name $folderName

Get-View -ViewType VirtualMachine -Filter @{"Parent"=$tgtFolder.ExtensionData.MoRef.Value} |Select Name

The folder should be the folder where are virtual machines.

In the case of nested folders, the script requires little additional code.

Tags: VMware

Similar Questions

  • 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

    }

  • specify the name of the vm to get-view-filter of hash

    According to me, Miss me some eccentric or a convention with Powershell variables in a hash filter.

    My infrastructure includes these 3 VMs:
    UTIL
    otherUTIL
    anotherUTILserver

    I try to use something like the following to return only the virtual machine called UTIL. This returns all 3 VMs with UTIL in their name:

    $vm = 'UTIL '.

    Notice-EEG - ViewType VirtualMachine-filter @{"Name" = $vm} | Select - expand name

    Get line - see below eliminates anotherUTILserver but always returns otherUTIL with UTIL:

    Notice-EEG - ViewType VirtualMachine-filter @{'Name' = ' $$vm '} | Select - expand name

    With ' $vm$ ' I'm following comment by LucD here: http://rvdnieuwendijk.com/2011/09/12/how-to-use-VMware-vSphere-PowerCli-to-find-the-MAC-addresses-of-a-virtual-machine/#comment-22

    If necessary, I could use the GET more slow-but-more simple-vm, could add a foreach loop (my example is simplified), or might filter on an additional property in addition to the name. But I hope that there is a similar thing that will help you eliminate otherUTIL and filter return only UTIL, without adding complexity.

    Regular expression to the rescue: http://msdn.microsoft.com/library/az24scfc.aspx

    Notice-EEG - ViewType VirtualMachine-filter @{"Name" = "^ $vm$"} | Select - expand name

    Or without regex:

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

    $x | where {$_.name - eq $vm} | Select - expand name

  • with Get-VIew-filter

    How can I search a host using its MoRef, code below does not work:

    Get-view viewtype - HostSystem-filter @ {"HostId"="host-139"}

    Luke,

    I was referring to the construction of the ManagedObjectReferen object.

    I wonder why you can not use the MoRef property. Maybe it's a bug.

    Can I use other moref properties, but NOT the property of MoRef

    The following example works:

    $v = get-view - ViewType virtualmachine-filter @{"runtime.host"="" ^ $host-2116 "}

    This wil return all virtual machines from the host-2116. The porperty runtime.host is of type ManagedObjectReference.

  • 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 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.*"}
    
  • 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}}

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

  • Option 'Open folder to view files' missing from Autoplay prompt

    Original title: open the folder to view the files passed.
    Windo ws 7 ultimate. Recently noticed when I plug a USB key or external hard drive option 'Open folder to view files' is missing.

    I went in the "show more options to AutoPlay in Control Panel" and none of the any of drop downs are able to simply open the folder.

    Hello

    What is the option 'Open folder to view files' missing all the devices and media?

    Follow these steps and check if it solves the problem:

    Step 1:
    a. Click Start, click Control Panel.
    b. click on Autorun.
    c. in the AutoPlay window, scroll down and click on reset all default settings.
    NOTE: When you reset the default settings, it will give all game actions automatic in a State to choose A default.

    See the screenshot below:

    Now check if you get the option 'Open folder to view files' in the menu dropdown.


    Step 2:
    Auditor of files (SFC) system scan on your computer.

    Scan SFC will Windows replace corrupted or missing system files on your computer.

    Scan sfc enforcement procedure:
    a. Click Start, click principally made programs, accessories, right-click on command prompt and select run as administrator.
    b. click on continue or provide administrator credentials if prompted.
    c. in the type in the following command prompt window and press ENTER:
    sfc/scannow

    Refer to this article for more information:
    http://support.Microsoft.com/kb/929833 

    Kind regards
    Afzal Taher-Microsoft Support.
    Visit our Microsoft answers feedback Forum and let us know what you think.

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

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

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

  • Get-view do not show anything for some servers

    One of my colleagues has created a script to extract some VM PCI slot numbers the script seems simple like this and work for (most) servers.

    $ServerName = "Test01".

    $vmview = (get-View - ViewType VirtualMachine-filter @{"Name" = $ServerName}).config.hardware

    $AllSasControllers = $vmview. Device | Where {$_.} DeviceInfo.Summary - eq 'SAS LSI Logic'}

    foreach ($SasController to $AllSasControllers)

    {

    Write-Host "Pci slot number:" $SasController.SlotInfo.PciSlotNumber

    }

    It worked before, but since a few days on 3 virtual machines which are one of the 6 we want to check returns no results more. All 3 VM is connected to the same vCenter, while others are connected to another. Knowing this, we'll try another VM in the vCenter (defective)... .strange return these results...

    On a defective VM, I note that:

    $AllSasControllers is filled with the results

    But the slotinfo property is empty, so far I can only see this behavior on 3 virtual machines that worked fine before.

    We did a few add/remove disk shares a few weeks on all VM 6 on the two vCenters. (may be a clue)

    One has obtained clues where to look?

    After a restart of vCenter problem seems to have disappeared, requires that certain inconsistencies of data or something.

Maybe you are looking for