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.

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?

  • 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

    }

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

  • 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

    }

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

  • 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

  • How can I get my photos from Windows Gallery to view and print in color, not just black and white?

    How can I get my Windows Gallery pictures to view and print in chiputa, not just black and white?

    Hi Petergrossman,

    Welcome to the Microsoft Vista answers Forum!

    I need few details about the question you posted.

    * What are the name and model of the printer?
    * You receive driver updates for your printer through Windows Update?
    * The printer prints the other applications in color?

    In the meantime, try the following steps.
     
    1. try to print the default pictures in Windows Photo Gallery and check if you get a printing color.
     
    2. try to uninstall the printer driver and reinstall it.

    Also check the setting of the color of the printer. Go to printer settings and make sure that you have selected the option to color.

    To print a picture, follow these steps: -.

    If you have a printer connected to your computer, you can make prints of digital photos. The quality of your photos depends on several factors, including the type of printer paper, ink and the settings of the printer of your choice. You can control many of these settings when you print the picture, but keep in mind that the overall quality and resolution of the digital picture you are printing will affect your final result.

    1. open Windows Photo Gallery by clicking on the Start button, all programs, and then clicking Windows Photo Gallery.

    2. click on the image you want to print.

    To select more than one picture, hold down the CTRL key while you click the pictures that you want to select.

    3. on the toolbar, click on print and then click on print.

    4. in the print pictures dialog box, select the printer, paper size, qualite quality print, style print and number of copies to print.

    5. When you have finished choosing how you want to print your photos, click Print to start printing.

    Choose printing options follow these steps: -.

    Before you send a print job to the printer, decide if you want to print all or part of the document or Web page. You may, for example, annotate the pages to print or select a part of a document before sending it to the printer.

    Here are common printing tasks to consider:

    1. to print that a hollering part of a document or a file, make a note of the page numbers for each page you want to print.
    2. If you want to print part of a page or a Web page only, select the content to print before printing.
    3. If you want to print a specific page, click anywhere on the page before choosing the print options for the document.
    4. the page that you clicked becomes the current page and you can print it by selecting this option in the print dialog box.

    After deciding what to print, choose how the print copies should look, and then select a printer.
    Use print preview

    To see what the print will look like before you print it, open the document in a program that offers a preview before printing. Print preview is generally located in the file menu of a program. You should be able to get an overview of each page of the document. In some programs, you can choose print in preview mode options and then print directly from the preview. In other programs, you will need to close the preview, change the document or your printer settings and print.

    If you preview or print a document, and it does not appear the way that you intended, you will need to change the document or change your print options. For example, if one part of your document fits on the printed page, you may need to reduce the font size, reduce the margins, or change the page layout and then try to print again.

    Check out these links that talk about how to print a picture using Windows Photo Gallery:

    http://Windows.Microsoft.com/en-us/Windows-Vista/print-a-picture

    http://Windows.Microsoft.com/en-us/Windows-Vista/choosing-print-options#section_2

    Thank you, and in what concerns:
    Shalini Surana - Microsoft technical support.
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Want to get an overview with the photo viewer and open with Photoshop

    Hello.  In all previous versions of Windows, I was able to do.  Right-click on an image and the 'Preview' option would open the image in the Windows Photo Viewer, and the option 'Open' it would open in Photoshop (or whatever the editor, I had chosen).  I just installed Windows 7 and I seem to be unable to get to do this.  If I select "Photo Viewer" as the default program for jpg files, I have TWO options 'Preview' in the right click menu.  Both will open it in Photo Viewer.  If I select Photoshop as the default program for jpg files, I get a 'Preview' and 'Open' option, but both open the image in Photoshop.

    How can I configure "Preview" with Photo Viewer, and 'open' with Photoshop?

    Thanks for the tips of registry.  I managed to find and fix the problem.  I tried to fix paint.net as the program open by default, and it has open in paint.net and presented in preview in Photo Viewer.  So I thought it was something to go astray with Photoshop.  Under HKEY_Classes_Root\Photoshop.JPEGFile.9\shell, there is a key-file for 'Preview '.  I deleted who, and now it opens in photoshop and previews in Photo Viewer.

  • Can be combined in the same script Get - VM and Get - view?

    Hello

    I am trying to find a way to combine these two Get - VM and Get - view in the same script.

    Script # 1

    Get-Cluster Management | Get - VM | Select Name,@{Name="HardwareVersion; Expression = {$_.} ExtensionData.Config.Version}}

    Script # 2

    Get-Cluster Management | Get - vm | where {$_.powerstate - don't "PoweredOff"} | % {get-view $_.id} | Select Name, @{Name = "ToolsVersion"; {Expression = {$_.config.tools.toolsVersion}}, @{Name = "ToolStatus"; Expression = {$_.} Guest.ToolsVersionStatus}}

    I've always had problems try this out and now, I need to combine them into a single script in figure.

    If you can help me or point me in the right direction would be great.

    Thank you

    Mike

    Curiosity got the best of me so I came with this. You had more correct, but you need to make a custom object so that the properties you are looking for can all be used simultaneously.

    It does not use the pipeline and uses a foreach loop.

    ----------------------------------------------------------------------------------------------

    $vms = get-Cluster Management | Get - VM? {$_.powerstate - don't "PoweredOff"}

    {foreach ($vm to $vms)

    $VMID = get-View ($vm.id)

    New-object psobject-property @ {}

    VM = $vm

    HardwareVersion = $vm. ExtensionData.Config.Version

    ToolsVersion = $VMID.config.tools.toolsVersion

    ToolsStatus = $VMID. Guest.ToolsVersionStatus

    } | Select the virtual machine, ToolsVersion, HardwareVersion, ToolsStatus

    }

    ----------------------------------------------------------------------------------------------

    Or use this option if you like the pipeline with Foreach-Object approach.

    ----------------------------------------------------------------------------------------------

    Get-Cluster Management | Get - VM? {$_.powerstate - don't "PoweredOff"} | % {

    $VMID = get-View ($_.id)

    New-object psobject-property @ {}

    VM = $_

    HardwareVersion = $_. ExtensionData.Config.Version

    ToolsVersion = $VMID.config.tools.toolsVersion

    ToolsStatus = $VMID. Guest.ToolsVersionStatus

    } | Select the virtual machine, ToolsVersion, HardwareVersion, ToolsStatus

    }

    ----------------------------------------------------------------------------------------------

    Both methods are correct that I can see. I tried both and both work well. You can easily piple only out to Export-Csv at the end of the select line. I hope this helps.

    Andrew

    Post edited by: andrewsardinha
    condition of powerstate added to each block operator and foreach-object script to the last script block.

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

  • Get-view datastore and get-function data store

    Hey, my first time posting here.

    Creating a function which takes as input pipeline and processes that each entry through process in a function. I want the function to be able to take the 'get - view - viewtype datastore' and 'get-datastore' as input.

    Obtained in what concerns obtaining the opinion of the GET and get-datastore work separately in the service, but when I want the function to be able to take one or the other input that I can't make it work.

    Here is the function at this moment, not really work for one of the entries.

    Function Get-DatastoreSpace () {}
    [cmdletbinding()]
    (param
    [Parameter (mandatory = $true,)]
    ValueFromPipeline = $true)]
    $Datastore
    )

    BEGIN {$ReportDatastore = @ ()}

    {IN PROCESS

    $row = "" | Select-Object Datastore_name, Datastore_Freespace_GB, Datastore_type, Datastore_Capacity_GB
    $row. Datastore_name = $_.name
    $row. Datastore_type = $_.type
    $row. Datastore_Capacity_GB = [math]: tour ($_.) Capacity / 1 gb, 3)
    $row. Datastore_Freespace_GB = [math]: tour ($_.) FreeSpace / 1 gb, 3)

    $ReportDatastore += $row

    }

    END {$ReportDatastore}

    }

    Any ideas on how to do this?

    Thanks in advance

    Eirik

    Check the type of the object in the variable $datastore.

    Something like that

    if($datastore -is [VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl]){
    # From Get-Datastore
    }
    elseif($datastore -is [VMware.Vim.Datastore]){
    # From Get-View -ViewType Datastore
    }
    else{
    # Wrong object type
    }
    
  • 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.

  • can not get .pps to define the association in vista Email__I download MS Powerpoint Viewer and still get the message

    Does anyone know how to set this association under Vista?

    Does anyone know how to set this association under Vista?

    Use this tutorial:

    Cannot open. PPS directly from Windows Mail or Windows Live Mail attachments
    http://www.Winhelponline.com/blog/unable-to-open-PPS-ppt-from-Windows-mail-or-WLM/

    Also check the file association for .pps setting...

    Start > default programs > associate a type of file or Protocol with a specific program > under the NAME on the right, scroll down to find .pps, up until it clicks > look acroos to the right, under current default, he should tell Microsoft Office PowerPoint Viewer...
    If it is not at the top, click on Change Program... > find Microsoft Office PowerPoint Viewer and click > click OK when finished. For the benefits of others looking for answers, please mark as answer suggestion if it solves your problem.

Maybe you are looking for

  • iTunes 12 does not update 3rd Gen iPad to iOS9

    Hello. I decided to take the plunge and understand my 3rd gen iPad will iOS9 and that iTunes 12 it will synchronize. If this is incorrect can someone please confirm this? I read the advice that I shouldn't update the iPad via Wifi so I the joint via

  • I'm getting flickering of software

    Hello Software on my machine began to falter. For example Firefox kind of flickers market very quickly every ten seconds. Other software also that. It is very sensitive in my music software when I have an open plugin. the pliugin sparkles, almost as

  • Unable to connect to the network wireless in Windows XP.

    Original title: connect to my new network I have a new wireless network and everything goes well on my new laptop with Windows 7 but I couldn't connect my old laptop running XP to my new network.  I followed all the instructions, especially taking a

  • Full updates from windows computer

    I reset my computer to original settings after I had filled the hard drives. Since the reset of all this I ran is updates of windows and drives are 80% full just with the Windows updates. The system is Vista, and readers are 80 GB each. My question i

  • Taskbar of liaison and the Dell dock.

    I had recently installed my dell dock, before I lost it, it was as related to my taskbar, for example, it would change color whenever we change the color of the dell docking station to match. My question is how to link the?