arrays - 用于报告多个共享上的旧文件夹的 Powershell 脚本
问题描述
我希望得到一些指导。我需要分析 6 个月内未修改的文件夹的多个共享。对于每个共享,我定义了需要检查的特定路径。应为每个共享生成一个 csv。powershell 脚本可以很好地检查单个共享,但我无法让它对多个共享正常工作。这是脚本的示例。
$age = (Get-Date).AddMonths(-6)
# Export path
$outputPath = "D:\Scripting\xPowershell_Results\"
# Export file name
$FilePath1 = "OldMediaPath1.csv"
$FilePath2 = "OldMediaPath2.csv"
# Paths to scan
$CheckPath1 = @(
"\\servername\share1\Projects"
"\\servername\share1\Restored"
)
$CheckPath2 = @(
"\\servername\share2\Graphics"
)
$folders = dir $CheckPath1 | where {$_.PSiscontainer -eq $true} | Where-Object {($_.LastWriteTime -lt $age)}
$results = foreach ($folder in $folders) {
$bytecount = (dir $folder.fullname -recurse | Measure-Object -property length -sum).sum
switch ($bytecount)
{
{$_ -lt 1KB} { $size = "{0:N0} Bytes" -f $_; break }
{$_ -lt 1MB} { $size = "{0:N2} KB" -f ($_ / 1KB); break }
{$_ -lt 1GB} { $size = "{0:N2} MB" -f ($_ / 1MB); break }
{$_ -lt 1TB} { $size = "{0:N2} GB" -f ($_ / 1GB); break }
{$_ -lt 1PB} { $size = "{0:N2} TB" -f ($_ / 1TB); break }
default { $size = "{0:N2} PB" -f ($_ / 1PB) }
}
[PSCustomObject]@{
Name = $folder.fullname
Size = $size
LastWriteTime = $folder.LastWriteTime
}
}
$results | Export-Csv $outputPath$FilePath1 -NoTypeInformation
解决方案
推荐阅读
- android - 如何在recyclerView中管理点击事件
- c++ - 如何在 std::map 中找到具有最大值 C++ 的所有键?
- class - 例如,类的 Haskell 方法不可见
- junit5 - 如何从 StackTraceElement 创建 JUnit 5 DynamicTest testSourceUri?
- python - python气流:使用集群和分区创建destination_dataset_table?
- typescript - 如何使用数组的替换变量生成所有组合?
- ubuntu - 在 ubuntu 中,是否有一些命令表示“追加”和“包含”?请让我看看
- android-studio - 我们从 Android Studio 切换到 Unity 并且无法唱歌
- flutter - 如何在flutter中监听整个页面的点击事件
- java - 在java中有效过滤字符串