我需要从PowerCli字符串中读取以太网适配器名,这样我就可以通过脚本,而无需用户交互,使用它来更改windows机器上的ip地址。
下面是powerCli字符串的外观,我将从其中读取子字符串:
C:\> $myIpInfoStringScriptOutput
|
Windows IP配置\x{e76f}
\x{e76f}以太网适配器局域网连接6: x
连接特定的DNS后缀。:
自动配置IPv4地址。。*255.255.255
子网面具。。。。。。。。。。。*255.255.255
默认网关。。。。。。。。。:
|
如何以另一个字符串变量结束,该变量包括以下内容:
C:\>$myGoalString
Local Area Connection 6这一点之所以重要,是因为数字6从一台机器更改到另一台机器,并且可以是,例如,"Local 15“。
发布于 2014-07-16 16:52:57
使用Select-String
$myGoalString = $myIpInfoStrong |
Select-String '^[\s\S]*?Ethernet adapter (.*?):' |
select -Expand Matches | select -Expand Groups |
select -Last 1 Value使用PowerShell v3或更新版本,您可以将其简化一点,如下所示:
$myGoalString = $myIpInfoStrong |
Select-String '^[\s\S]*?Ethernet adapter (.*?):' |
% { $_.Matches.Groups[1].Value }https://stackoverflow.com/questions/24786163
复制相似问题