使用.FullName属性而不是目录名称,如此.
.FullName
dir $path -Recurse | measure | select Count Count ----- 4 PS C:\users\Stephen> dir $path -Recurse | ? FullName -ne "R:\Exclude\Include1\Exclude" | >> measure | select Count Count ----- 3