我有这个代码:
powershell -Command "(Get-Content C:\users\Public\ITCMD\Toggler\settings.ini) | Where-Object {$_ -notmatch "\b!Friend!\b"} | Set-Content C:\users\Public\ITCMD\Toggler\settings.ini"
我订了!朋友!到文本值。该脚本正在吐出这些错误:
At line:1 char:86
+ ... blic\ITCMD\Toggler\settings.ini) | Where-Object {$_ -notmatch \buhgft ...
+ ~
You must provide a value expression following the '-notmatch' operator.
At line:1 char:87
+ ... \Toggler\settings.ini) | Where-Object {$_ -notmatch \buhgft\b} | Set- ...
+ ~~~~~~~~~
Unexpected token '\buhgft\b' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
想知道它为什么这样做?谢谢!
您的双引号被cmd解释为命令的结尾并导致PowerShell的解析问题。如果用单引号替换它们,它将修复解析问题:
powershell -Command "(Get-Content C:\users\Public\ITCMD\Toggler\settings.ini) |^
Where-Object {$_ -notmatch '\b!Friend!\b'} |^
Set-Content C:\users\Public\ITCMD\Toggler\settings.ini"