
我想在 PowerShell 中按物件類型過濾物件清單。當然,我可以使用類型名稱和字串比較來做到這一點:
PS C:\> gci -r | where { $_.GetType().Name -eq "DirectoryInfo" }
但我紮根於 C#,所以一直在尋找類似is
運算符的東西。
我的方法是最好的還是有其他方法?
答案1
PowerShell 有一個-is
運算子:
gci -r | where { $_ -is [System.IO.DirectoryInfo] }