我猜您在cmdlet中缺少braces{}
for your 。运算符也使用通配符进行搜索操作。scriptblock
Where-Object
-notlike
Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue' | Where-Object {$_.Attributes.ToString() -NotLike "*ReparsePoint*"}
根据 cmdlet 的msdn文档Where-Object
,您将看到有两种方法可以构造 Where-Object 命令。
方法一
脚本块。
您可以使用脚本块来指定属性名称、比较运算符和属性值。Where-Object 返回脚本块语句为真的所有对象。
例如,以下命令获取 Normal 优先级类中的进程,即 PriorityClass 属性值等于 Normal 的进程。
Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}
方法二
比较声明。
你也可以写一个比较语句,它更像自然语言。Windows PowerShell 3.0 中引入了比较语句。
例如,以下命令还获取优先级为 Normal 的进程。这些命令是等效的,可以互换使用。
Get-Process | Where-Object -Property PriorityClass -eq -Value "Normal"
Get-Process | Where-Object PriorityClass -eq "Normal"
附加信息 -
从 Windows PowerShell 3.0 开始,Where-Object 将比较运算符作为参数添加到 Where-Object 命令中。除非指定,否则所有运算符都不区分大小写。在 Windows PowerShell 3.0 之前,Windows PowerShell 语言中的比较运算符只能在脚本块中使用。
在您的情况下,您正在构建Where-Object
as ascriptblock
并因此braces{}
成为必要的邪恶。或者,您可以Where-Object
通过以下方式构建您的 -
Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue' | Where-Object Attributes -NotLike "*ReparsePoint*"
(或者)
Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue' | Where-Object -property Attributes -NotLike -value "*ReparsePoint*"