过滤 Invoke-RestMethod 结果

Filter Invoke-RestMethod results

我正在通过 GET Invoke-RestMethod 从我的应用程序中提取有关提供商的一些详细信息。 目前,它正在 returning 有关提供商的所有详细信息。我只想 return 活动状态设置为 True 的提供商代码。

$acctname = 'user1'
$password = 'secret'

$params = @{uri = 'http://localhost:8080/tryout/settings/provider/providerDetails';
                   Method = 'Get';
                   Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"))
           } #end headers hash table
   } #end $params hash table


# This gets all the basic info ok
$var = invoke-restmethod @params

#show the values in the console
echo $var

目前return所有这些细节。我只需要代码 if active-true.

id            : 90
name          : Test 1
active        : True
code          : NOT_STATED
system        : False
objectVersion : 2

id            : 91
name          : Test 2
active        : True
code          : MAIN
system        : False
objectVersion : 3

id            : 20372
name          : Test 3
active        : True
code          : NOT_STATED
system        : True
objectVersion : 2

id            : 30382
name          : Test 4
active        : True
code          : OP
system        : False
objectVersion : 1

只需 管道 $varWhere-Object cmdlet 并过滤它们:

$var | Where-Object active -eq 'True'