ipconfig | Select-String "IPv4 Address"
返回如下内容:
IPv4 Address. . . . . . . . . . . : 192.168.1.50
IPv4 Address. . . . . . . . . . . : 172.20.112.1
IPv4 Address. . . . . . . . . . . : 192.168.208.1
假设我想使用-replace用空字符串替换“IPv4 地址...... 我该怎么做?这是我尝试过的:
ipconfig | Select-String "IPv4 Address" -replace "IPv4 Address. . .",""
这给了我以下错误:
Select-String : A parameter cannot be found that matches parameter name 'replace'.
At line:1 char:41
+ ipconfig | Select-String "IPv4 Address" -replace "IPv4 Address. . .", ...
+ ~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-String], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SelectStringCommand
有任何想法吗?
您将重写它以
-replace
使用不同的语法执行操作。这样它就不必寻找Select-String
函数的参数。正如那里的错误所示:
Select-String : A parameter cannot be found that matches parameter name 'replace'
这正是问题所在——Select-String
没有-Replace
参数。有效语法
或者
或者将命令的第一部分保存到变量中,然后运行替换操作
输出
支持资源