Powershell 排除Get ChildItem中的连接点
我想获得Powershell 排除Get ChildItem中的连接点,powershell,get-childitem,junction,Powershell,Get Childitem,Junction,我想获得C:\驱动器中所有用户创建文件夹的列表。然而,由于连接点的原因,我得到了错误的结果。 我试过了 但是我有一个 不能对空值表达式错误调用方法 我猜您在Where-Objectcmdlet中缺少了scriptblock的大括号{}。另外,-notlike操作符使用通配符进行搜索操作 Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue'
C:\
驱动器中所有用户创建文件夹的列表。然而,由于连接点的原因,我得到了错误的结果。
我试过了
但是我有一个
不能对空值表达式错误调用方法
我猜您在
Where-Object
cmdlet中缺少了scriptblock
的大括号{}
。另外,-notlike
操作符使用通配符进行搜索操作
Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue' | Where-Object {$_.Attributes.ToString() -NotLike "*ReparsePoint*"}
根据Where-Object
cmdlet的文档,您将看到有两种方法可以构造Where-Object命令
方法1
脚本块
您可以使用脚本块来指定特性名称、比较
运算符和属性值。其中对象返回对象的所有对象
其中脚本块语句为true
例如,以下命令以正常方式获取进程
优先级类,即
PriorityClass属性等于法线
Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}
方法2
比较语句
您还可以编写一个比较语句,它更像
自然语言。Windows中引入了比较语句
PowerShell 3.0
例如,以下命令还获取具有
正常的优先等级。这些命令是等效的,可以
可以互换使用
Get-Process | Where-Object -Property PriorityClass -eq -Value "Normal"
Get-Process | Where-Object PriorityClass -eq "Normal"
其他资料-
从Windows PowerShell 3.0开始,对象在其中添加比较
运算符作为Where对象命令中的参数。除非另有规定,
所有运算符都不区分大小写。在Windows PowerShell 3.0之前,
Windows PowerShell语言中的比较运算符可能是
仅在脚本块中使用
在您的例子中,您正在将Where对象
构造为脚本块
,因此大括号{}
成为一种必要的邪恶。或者,您可以通过以下方式构造Where对象
:
Get-ChildItem "\\localhost\c$" -Directory -force -Exclude $generalExclude -erroraction 'silentlycontinue' | Where-Object Attributes -NotLike "*ReparsePoint*"
(或)
其中对象属性-NotLike“*repassepoint*”
作为-NotLike
比较运算符需要通配符。
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*"