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.

Tags: VMware

Similar Questions

  • 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
    }
    
  • 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}
    
  • Still not get the filtering and the SUMIF with visible cells

    Hi all

    I know it is a pain for you people, but I'm really stuck with this problem.

    I tried to use the answers I found in the community and the User Guide, but I have to be closed to this kind of explanation.

    Once again:

    In the column A is a series of dates

    In column B the value corresponding

    In the foot of B line, I want the SumOf only the visible cells that I filtered before.

    So far I have always the sum of all the lines, filtered or not.

    I added another column with a True/False value and tried to use it but get the same result.

    I'm pretty slow, so I guess that I'll need your help once more.

    It is the sum before filtering:

    And that's the sum after filtering:

    I thank you for your time and patience.

    Lopez

    Lopez Hello,

    Table filtering only affects the rows that are displayed. Hidden lines are always included in the calculations of formulas referring to them.

    Your formula, = SUM (B2:B16) summarizes the content of all the B2 to B16 cells, including those that are hidden.

    There are several other functions in the family of the SUM. SUM, SUMIF and SUMIF. ENS are of interest here.

    SUMIF (English: SUMIF) accepts a condition and only adds the cells on the lines which is assembled as a condition.

    SUMIF. ENS (English: SUMIFS) accepts several conditions and only adds the cells on the rows that meet all the conditions.

    For the example stated in your post, must be the form you need:

    = SUMIF. ENS(B; A; "> = 02/01/2016." A; "" < 03/01/2016 ")"

    (NOT tested. The dates should be placed in two cells and these cells referenced in the formula. post a reply with any error message if the formula does not work as written).

    The lines not included in the amount need not be hidden.

    If the formula is inserted into column B, it must be in a line defined as a footer line using the menu item in the same position as the highlight in this screenshot:

    Footer lines can be placed on foot (bottom) of a table.

    Kind regards

    Barry

  • display initial, intermediate and final conditions in an indicator

    I have two indicators, one aping a multicolor LED and the other a text string.  I use an event inside a while loop to monitor a push of button that triggers a response.

    At the beginning of the program, I want to put an initial condition for these two indicators for example the LED is off and string "to go". »

    As the program is running, the LED color changes and updates of string according to a logic.

    The program is tired of running it is account to 10 and decided to stop, affecting the LED and the chain to a timeout condition.

    In addition, the user can hit the stop button, in which case the LED and the chain show a stop condition.

    Problem is if I put the indicators on the registers on the left, I get the correct initial condition but to an incorrect final condition.  If I put the indicators on the right records, I'm getting correct finals but incorrect initial conditions.  How can I get the initial AND final conditions correct?

    A slap in the right direction would be much appreciated.

    Use the time-out period.  Using a registry to offset, you can set the time-out of the structure of the event to be 0 for the first iteration and -1 for all other iterations.  Yes, then you can update your indicators on the right.  In the case of the time-out period, it is just wire your straight through statutes.

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

  • PowerCLI - get the number of cores per processor and number of Sockets

    Greetings,

    We are responsible to give a list of all our virtual machines with their host name, the number of CPUs, the BONES and the number of cores per processor for verification.

    I immediately said that this would not be a problem with PowerCLI. However I seem to have more trouble with it than expected.

    Get the number of CPUS is not a problem, but the time wherever I want to divide the number of cores and the number of sockets, it seems to hit a dead end.

    I found the following entries of the community concerned:

    Re: vSphere 5. Casings of vCPU and cores per CPU (PowerCLI) bug

    Machine virtual access avancΘs | VMware vSphere Blog - VMware Blogs

    Parameters to retrieve and set Advanced Configuration (VMX) VM

    But neither seemed to give me the right input. The advanced configuration settings do not appear to contain the number of cores/sockets and Get-View and Get - VM normal controls do not seem to differentiate between carrots and the power outlets and just give the number of processors.

    Because we need these settings for a check I doubt I'm the first to need this information. Does anyone have an idea how to get this information?

    Please note that it is the number of cores and casings of a VM, not an ESXi host.

    Thanks in advance,

    Bram

    $result = @)
    $vms = get - view - ViewType VirtualMachine
    {foreach ($vm to $vms)
        $obj = new-object psobject
        $obj | Add-Member - MemberType NoteProperty-name name - value $vm. Name
        $obj | Add-Member - MemberType NoteProperty - name CPUSocket-$vm.config.hardware.NumCPU value
        $obj | Add-Member - MemberType NoteProperty - name Corepersocket-$vm.config.hardware.NumCoresPerSocket value
        $result += $obj
      
    }
    $result
  • 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.

  • How to get the angles of view (horizontal and vertical) camera?

    How to get the angles of view (horizontal and vertical) camera?

    The horizontal and vertical field of VIEW properties are available with the camera_get_physical_property() function.

    Who is using the C API of the photo. I don't think that you can access by using the control of the camera of Cascades.

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

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

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

  • total vm host running and availability with get-view

    Ways to find "on the virtual machine host total running" & availability with get-view, get-view gives the boot time, but no availability, we convert the startup time of availability?

    Hello, esxi1979-

    You can use something like:

    Get-View -ViewType HostSystem -Property name,Runtime.BootTime,Vm | Select name,    @{n="NumVM"; e={$_.Vm.Count}},    @{n="Uptime"; e={New-TimeSpan -Start $_.Runtime.BootTime}}
    

    The Uptime property is a Timespan object.  How does do for you?

  • How to get the width and height of Flex Mobile view?

    Hello

    The following instructions can get the width and height of the current Flex app:

    var request: UIComponent = FlexGlobals.topLevelApplication as UIComponent;

    trace (application. Width);

    trace (application. Height);

    But I don't know how to get the width and height of mobile display Flex current (i.e. the content size excludes bar action and the Navigation bar). Why the "this.width" always returns 0?

    Thank you!

    Looks like you're running in this bug: https://bugs.adobe.com/jira/browse/SDK-30070

Maybe you are looking for

  • How can I completely remove/uninstall Firefox on my macbook pro?

    I followed the directions that I see posted online to remove Firefox on mac, which say you should drag the application "trash". I did, and he said: "You cannot move trash Firefox because Firefox cannot be deleted." Help, please! Thank you!

  • STAR WARS 15-an001na HP: slot m2 15-an001na HP STAR WARS SPECIAL EDITION?

    Hello. I would like to ask any SSD on my STAR WARS 15-an001na HP, but I can't find record of ditailed to see if the MB has additional location SATA or m2. Can u pls addvise. THX.

  • signal of reverse USRP

    Hello!! I'm trying to built a small radar with the USRP 2920... but I have a problem. I connect the two ports of the USRP (TX1-RX2) with a cable with low loss of 50 cm... after transmission of a chirp signal, sometimes I found my IDE oucederomsurlese

  • HELPPP

    My sansa is like climbing I can't get the next loading screen

  • Play65 doesn't ' work why?

    Play65 doesn't ' knit 6 days why?