先感谢您!我希望有人可以帮助我解决以下问题。我可以找到超过 30 天的文件夹和子文件夹(如您在脚本中所见),但我想添加 2 个功能。
- 如果没有子文件夹,则必须跳过。
- 如果没有超过 30 天的子文件夹,则必须跳过。
我能够添加以下条件“如果没有名为 OwnerEmail.txt 的文件,它将跳过”
if (-not(Test-Path $path)){Continue}
非常感谢您的帮助。下面是脚本
$InitialFolder = "C:\Test\WRA"
$Sender = "cubam1@company.com"
$SenderReportFile = "C:\Test\WRA\file.csv"
# ==============================================
$ParentFolders = Get-ChildItem -Path $InitialFolder -Directory |
Select-Object -ExpandProperty FullName
foreach ($SubFolder in $ParentFolders) {
$path = Join-Path $SubFolder -ChildPath 'OwnerEmail.txt'
# ================ If OwnerEmail.txt does not exist, skip ================
if (-not(Test-Path $path)){Continue}
# ================ Building HTML Report ================
$WRAHTMLReport = Get-ChildItem -Path $SubFolder -Directory |
Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} |
Select-Object Name, CreationTime |
..
.
.
.
.