PowerShell总文件计数和计数文件比日期更新
我想获得比特定日期更新文件计数的总文件计数,而不必进行2个单独的呼叫。有没有办法在1个电话中获得这两个计数?
效率低下的方式:
cls
$compareDate = (Get-Date).AddDays(-365)
$FileShare = "C:\Folder\Subfolder"
$TotalCount = (Get-ChildItem -File -Recurse $FileShare | Measure-Object).Count
$ActiveCount = (Get-ChildItem -File -Recurse $FileShare | Where-Object { $_.LastWriteTime -gt $compareDate}).Count
$Percentage = ($ActiveCount/$TotalCount)*100
Write-Host $ActiveCount/$TotalCount " is " $Percentage.ToString("#.##") "% Active"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解,您只需要拨打
Get-Childitem
一次,然后根据此集合过滤以获取第二个计数($ activeCount
):还值得注意的是,由于集合(
$ files
)已经在内存中,因此。where
方法比where-object> where-object
cmdlet> cmdlet 用于过滤。如果您需要的速度比
.。
If I understand correctly, you only need to make the call to
Get-ChildItem
only once, then filter based on this collection to get the second count ($ActiveCount
):It's also worth noting that, since the collection (
$files
) is already in memory, the.Where
method is more efficient thanWhere-Object
cmdlet for filtering.If you need something faster than the
.Where
filtering technique displayed above: