You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell技术问询:如何获取Name列第一行对应的值

获取PowerShell中联网网卡的Name列首行值

要从指定命令的输出中提取Name列第一行的值,可通过以下两种简洁的PowerShell命令实现:

方法一:使用Select-Object展开属性并限制行数

(Get-NetAdapter -InterfaceIndex $(Get-NetConnectionProfile | Where-Object IPv4Connectivity -eq "Internet").InterfaceIndex | Select-Object -ExpandProperty Name -First 1)
  • Select-Object -ExpandProperty Name:直接提取对象的Name属性值,而非返回带属性名的对象
  • -First 1:仅保留结果中的第一行数据

方法二:通过对象属性索引取值

((Get-NetAdapter -InterfaceIndex $(Get-NetConnectionProfile | Where-Object IPv4Connectivity -eq "Internet").InterfaceIndex).Name)[0]
  • 先获取目标网卡对象集合,直接访问其Name属性得到值数组
  • 索引[0]对应数组的第一个元素,即结果的第一行

执行上述任一命令,即可得到预期的“Ethernet 8”结果。

内容的提问来源于stack exchange,提问作者edmamerto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 05:27:02