在 PowerShell 中从列表中选择一个项目 [英] Select an Item from List in PowerShell

查看:42
本文介绍了在 PowerShell 中从列表中选择一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PowerShell 进行 api 调用.我从调用中得到 3 个输出.

I am making an api call using PowerShell. I get 3 outputs as results from the call.

ID : 1
Name :Abc
Location : London

我想将 ID 传递给一个新变量.我怎样才能在 powershell 中实现这一点.谢谢

I want to pass the ID to a new variable. how can i achieve this in powershell. Thanks

推荐答案

您可以使用 . 成员访问运算符:

You can either use the . member access operator:

$ID = (Call-ThatReturnsObject).ID

Select-Object -ExpandProperty:

$ID = Call-ThatReturnsObject |Select-Object -ExpandProperty ID

ForEach-Object:

$ID = Call-ThatReturnsObject |ForEach-Object -MemberName ID
# or 
$ID = Call-ThatReturnsObject |ForEach-Object { $_.ID }

这篇关于在 PowerShell 中从列表中选择一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆