Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;在;powershell中的条件_Powershell_Powershell 2.0 - Fatal编程技术网

&引用;在;powershell中的条件

&引用;在;powershell中的条件,powershell,powershell-2.0,Powershell,Powershell 2.0,Powershell中是否存在类似于sql的“in”条件。如果有,请让我知道如何使用它的语法。 我的建议是我需要得到一个ID列表,并在另一个查询中使用它 在下面找你做什么 //Below line i veried returns values more than 1 $desktopGroupIds = Get-BrokerDesktopGroup -AdminAddress 'IPAddressgoeshere' | select uid Get-BrokerPrivateDesktop

Powershell中是否存在类似于sql的“in”条件。如果有,请让我知道如何使用它的语法。 我的建议是我需要得到一个ID列表,并在另一个查询中使用它

在下面找你做什么

//Below line i veried returns values more than 1
$desktopGroupIds = Get-BrokerDesktopGroup -AdminAddress 'IPAddressgoeshere' |  select uid

Get-BrokerPrivateDesktop  -AdminAddress 'IPAddressgoeshere' | Where { $desktopGroupIds.contains($_.DesktopGroupUid) } | select DesktopGroupUid
第二个查询不返回值。如果我逐个传递值,我相信第二个查询可以给出结果。我想使用可能是“-in”运算符,如果可用或使上述包含工作

谢谢,

Powershell的“in”关键字通常用于在集合对象中单独选择项目

e、 g:

如果要像在解决方案中一样使用“Contains”,可以将$desktopGroupIds中的所有内容强制转换为数组,方法是将第一行放在@()中:

e、 g

编辑

您可以尝试的另一种解决方案是使用-match运算符:

e、 g:

Powershell的“in”关键字通常用于在集合对象中单独选择项

e、 g:

如果要像在解决方案中一样使用“Contains”,可以将$desktopGroupIds中的所有内容强制转换为数组,方法是将第一行放在@()中:

e、 g

编辑

您可以尝试的另一种解决方案是使用-match运算符:

e、 g:


-in
是一个反向
-包含在PowerShell 3.0中添加的
运算符(因此dasari..必须更新才能使用它)。对于contains,您可以使用
$array-contains-element
,而在PS3.0中,您可以使用
$element-in$array

您似乎在
$desktopGroupIdS-c contains$\中有输入错误。
。试试这个:

//Below line i veried returns values more than 1
$desktopGroupIds = @(Get-BrokerDesktopGroup -AdminAddress 'IPAddressgoeshere' |  select uid)

Get-BrokerPrivateDesktop  -AdminAddress 'IPAddressgoeshere' | Where { $desktopGroupIds -contains $_.DesktopGroupUid } | select DesktopGroupUid

-in
是一个反向
-包含在PowerShell 3.0中添加的
运算符(因此dasari..必须更新才能使用它)。对于contains,您可以使用
$array-contains-element
,而在PS3.0中,您可以使用
$element-in$array

您似乎在
$desktopGroupIdS-c contains$\中有输入错误。
。试试这个:

//Below line i veried returns values more than 1
$desktopGroupIds = @(Get-BrokerDesktopGroup -AdminAddress 'IPAddressgoeshere' |  select uid)

Get-BrokerPrivateDesktop  -AdminAddress 'IPAddressgoeshere' | Where { $desktopGroupIds -contains $_.DesktopGroupUid } | select DesktopGroupUid

修复此问题的更新代码行如下所示

Get-BrokerPrivateDesktop  -AdminAddress $regionAddress | Where { $desktopGroupIds  -Contains $_.DesktopGroupUid } | select DesktopGroupUid

注:上面使用“-Contains”

修复问题的更新代码行如下所示

Get-BrokerPrivateDesktop  -AdminAddress $regionAddress | Where { $desktopGroupIds  -Contains $_.DesktopGroupUid } | select DesktopGroupUid

请注意上面使用“-Contains”

修复程序不起作用,我得到错误”方法调用失败,因为对于执行该条件的每一行,[System.Object[]]不包含名为“Contains.”的方法。您的$DesktopGroupId作为数组返回是否正确?通过在其上运行$desktopGroupIds.GetType()进行检查,它应该返回为…基本类型:System.Array“$desktopGroupIds.GetType()”并且我返回了“System.Array”作为基本类型,名称为“object[]”,ispublic和isserial设置为trueHrm,请尝试检查可用的方法以确保,同时我添加了一个您可以尝试的编辑。我已经在自定义数组上尝试了这两种方法,它们都有效。谢谢你的帖子。但是我认为我们不应该使用match,因为我们在这里比较ID。匹配类似于“%x%”运算符()。对于执行该条件的每一行,[System.Object[]]不包含名为“Contains.”的方法调用失败,因此修复程序不起作用。您的$DesktopGroupId作为数组返回是否正确?通过在其上运行$desktopGroupIds.GetType()进行检查,它应该返回为…基本类型:System.Array“$desktopGroupIds.GetType()”并且我返回了“System.Array”作为基本类型,名称为“object[]”,ispublic和isserial设置为trueHrm,请尝试检查可用的方法以确保,同时我添加了一个您可以尝试的编辑。我已经在自定义数组上尝试了这两种方法,它们都有效。谢谢你的帖子。但是我认为我们不应该使用match,因为我们在这里比较ID。匹配类似于“%x%”运算符()。谢谢您的帖子。错别字只是我在这里发布的代码,现在已经修复了-包含在1.0中,我认为ref()和2.0 ref()中都有,所以我认为我需要3.0.no,这可能是不对的<代码>-IN仅在PS3.0中
-contains
已经存在很久了,关于'-in'你是对的。谢谢。谢谢你的帖子。错别字只是我在这里发布的代码,现在已经修复了-包含在1.0中,我认为ref()和2.0 ref()中都有,所以我认为我需要3.0.no,这可能是不对的<代码>-IN仅在PS3.0中
-contains
已经存在很久了,关于'-in'你是对的。ref()谢谢。我得到的错误是“方法调用失败,因为[System.Object[]]不包含名为“Contains”的方法”。那么我需要更改的是将数组类型转换为我要比较的int吗?如果是,如何解决?错误现已修复。错误是由于contains的无效语法导致的,该语法应使用“-contains”,而不像方法。下面是我更新的答案,它解决了这个问题。我得到的错误是“方法调用失败,因为[System.Object[]不包含名为“Contains”的方法”。所以我需要更改的是将数组类型转换为我要比较的int?如果是,如何解决?错误现已修复。错误是由于contains的无效语法导致的,该语法应使用“-contains”,而不像方法。下面是我的最新答案,它解决了这个问题
Get-BrokerPrivateDesktop  -AdminAddress $regionAddress | Where { $desktopGroupIds  -Contains $_.DesktopGroupUid } | select DesktopGroupUid