Get-ChildItem -Path C:\windows -Recurse -ErrorAction SilentlyContinue -Filter *.ps1 | Where-Object { $_.Extension -eq '.ps1' } 这将只返回指定的扩展名文件。 混合使用Get-ChildItem 参数 可以在同一命令中使用 Get-ChildItem cmdlet 的多个参数。在混合使用参数之前,请确保您了解通配符匹配。例如,以下命...
$a=Get-ChildItemD:/-Recurse|Where-Object{$_.PsIsContainer-eq$true} $a|Where-Object{$_.GetDirectories().Count-eq0-and$_.GetFiles().Count-eq0}|Select-ObjectFullName 向命令、函数和文件脚本传递文件 # 只列出目录:: Dir | Where-Object { $_ -is [System.IO.DirectoryInfo] } Dir | Where-Ob...
还有一个错误,-include和-exclude的路径位于根“”,不显示任何内容。在unix中,它会出错。排除像“foo...
-exclude不适用于子目录或-filter:
请您参考如下方法: 使用Where-Object并测试$_.CreationTime: Get-ChildItem 'PATH' -recurse -include @("*.tif*","*.jp2","*.pdf") | Where-Object { $_.CreationTime -ge "03/01/2013" -and $_.CreationTime -le "03/31/2013" }
Where-Object { $matches = ($_.Matches | Select-Object -Unique) $matches.Count -gt 1 -or $matches[0].Value -ne '127.0.0.1' } | Select-Object Path, Matches, FileName, LineNumber, Line | ConvertTo-Csv -NoType } Find-IPAddresses 'C:\some\folder' > 'outfile.csv' ...
$dirs = Get-ChildItem | Select-Object FullName | Where-Object {!($_.psiscontainer)} | foreach {$_.FullName} #Adds the results of the Get-ChildItem manipulation to the array $userdirs $userdirs.AddRange($dirs) #Testing each member of array ...
或者(使用Where-Object获得的每个对象的FullName属性):
Where-Object{($_.PSIsContainer)} | Foreach-Object{$_.Name} Measure the size of a folder: PS C:\> Get-ChildItem C:\Work\ -Recurse -Force |Measure-Object-property length -sum Measure the size of a folder and display in GB, (to also round the numbers use the-F operator): ...
但它只适用于$fileDirectory的第一级。这是递归工作的: