玩PS和我有一个简单的脚本。创建一个前瞻性匹配
ipconfig /all | where-object {$_ -match "IPv4" -or $_ -match "Description"}
这是伟大的,做我期望的。我想要做的事情是提前阅读,并只显示IPv4行之前的描述。或反向搜索,并获得IPV4和下一个描述,然后寻找下一个IPv4等
有没有办法做到这一点,而不是通过创建一个数组,然后通过数组旋转通过旋转解出有意义的部分?
在我的笔记本电脑结果此命令:
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
Description . . . . . . . . . . . : Killer Wireless-N 1103 Network Adapter
IPv4 Address. . . . . . . . . . . : 192.168.1.2(Preferred)
Description . . . . . . . . . . . : Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.20)
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
IPv4 Address. . . . . . . . . . . : 192.168.122.1(Preferred)
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
IPv4 Address. . . . . . . . . . . : 192.168.88.1(Preferred)
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3
Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #5
我要的是:
Description . . . . . . . . . . . : Killer Wireless-N 1103 Network Adapter
IPv4 Address. . . . . . . . . . . : 192.168.1.2(Preferred)
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet1
IPv4 Address. . . . . . . . . . . : 192.168.122.1(Preferred)
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
IPv4 Address. . . . . . . . . . . : 192.168.88.1(Preferred)
这将显示没有可能有用的IP的活动适配器。 +1 – 2013-02-21 19:47:39
我增加了另一个解决方案。起初我一定误解了你的问题。不过,现在你有了一些选择+如何用正则表达式提取描述的例子(IP是通过用“IP”替换“描述”和去除正则表达式中的美元符号来完成的):) – 2013-02-21 20:03:52
这是一个很好的选择,使用不同的方法,我可以选择PS作为'我的'工具箱中的相关工具。 – 2013-02-22 04:13:37