locked
-and operator not working RRS feed

  • Question

  • Hello, i would like to use -and operator in this situation:

    Get-vm -Name "WE*" -and "X"

    Get-VM : A parameter cannot be found that matches parameter name 'and'.

    At line:1 char:20

    + Get-vm -Name "WE*" -and "X"

    +                    ~~~~

        + CategoryInfo          : InvalidArgument: (:) [Get-VM], ParameterBindingException

        + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

    But without -and operator working:

    PowerCLI C:\> Get-vm -Name "WE*"

     

     

    Name                 PowerState Num CPUs MemoryGB

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

    WE5066               PoweredOn  4        4,000

    WE7249               PoweredOn  4        4,000

    WE7149               PoweredOn  4        4,000

    WE7244               PoweredOn  4        4,000

    It is another way or additional command required?

    Wednesday, August 23, 2017 6:38 AM

Answers

  • Get-VM does not have an "and"  operator.

    Get-vm | Where {$_.Name-like 'WE*' -and $_.Name -like 'X*'}

    Do you understand what a logical "and" is?  Are you sure you want "and"?


    \_(ツ)_/


    • Edited by jrv Wednesday, August 23, 2017 6:43 AM
    • Marked as answer by TechSpark0 Wednesday, August 23, 2017 7:27 AM
    Wednesday, August 23, 2017 6:42 AM

All replies

  • What are you trying to achieve ? there is no -and with Get-VM.


    Cdt, Loïc V. - NetSec Design - Blog: http://ms-sec.fr

    Wednesday, August 23, 2017 6:41 AM
  • Get-VM does not have an "and"  operator.

    Get-vm | Where {$_.Name-like 'WE*' -and $_.Name -like 'X*'}

    Do you understand what a logical "and" is?  Are you sure you want "and"?


    \_(ツ)_/


    • Edited by jrv Wednesday, August 23, 2017 6:43 AM
    • Marked as answer by TechSpark0 Wednesday, August 23, 2017 7:27 AM
    Wednesday, August 23, 2017 6:42 AM
  • What are you trying to achieve ? there is no -and with Get-VM.


    Cdt, Loïc V. - NetSec Design - Blog: http://ms-sec.fr

    How you checked that is no -and with get-vm?
    Wednesday, August 23, 2017 7:27 AM
  • Yes, okay, now i got it, -and can be used with $_.Name
    Wednesday, August 23, 2017 7:28 AM
  • A slightly confusing part of PowerShell is that parameters and operators both start with "-". In your line "-Name" is a parameter of Get-VM cmdlet. -And is an operator. Both have nothing in common.

    No, -and is used to combine logical statements. There are also -or and -xor. And I strongly guess, you want -or and not -and.

    I strongly advise to learn basic programming skills before doing anything else. 

    Wednesday, August 23, 2017 7:44 AM