Powershell相当于Python"in"?

Nac*_*ica 5 python arrays syntax powershell

我最近一直在使用数组,并且真的缺少Python的"in"运算符.

例如:

if ("hello" in ["hello", "there", "sup"]):
    print "this prints :)"
Run Code Online (Sandbox Code Playgroud)

我通过创建一个"ThereExists-Object"函数来弥补它,如下所示:

function ThereExists-Object([System.Management.Automation.ScriptBlock] $sb)
{
    return ($input | where $sb) -as [bool]
}
New-Alias -Name ThereExists -Value ThereExists-Object
Run Code Online (Sandbox Code Playgroud)

例如:

if ($arrayOfStuff | thereexists { $_ -eq "hello" } )
{
    write-host "this prints too"
}
Run Code Online (Sandbox Code Playgroud)

显然我也可以为此定义另一个函数......但是我想知道是否有一些我不熟悉的语法糖可以完成这项任务.

那么......有没有?

Cra*_*g O 9

$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors -contains "black" 
False
$arrColors -contains "blue"
True
Run Code Online (Sandbox Code Playgroud)

来源:http://technet.microsoft.com/en-us/library/ee692798.aspx