I need to add the function to delete any files older than 300 days in the folders that are read from the csv file.
$scanCsv = 'D:\Folders.csv'
$sendMailArgs = @{
From = 'email@email.com'
SmtpServer = 'mail.smtp.com'
Credential = Import-Clixml -Path "D:\MailCredential.xml"
UseSsl = $true # Uncomment to use SSL
Port = 587 # Uncomment to use SSL
}
Import-Csv -Path $scanCsv | ForEach-Object {
$fullName = $_.Path -f (Get-Date).AddDays(1).Date.ToString($_.DateTimeFormat)
Write-Host "Processing '$($fullName)' ($($_.Email))"
If (-not (Test-Path -Path $fullName)) {
$body = "Expected file '$($fullName)' not found!"
Write-Warning $body
Send-MailMessage @sendMailArgs -To $_.Email.Split(',').Trim() -Subject $_.Subject -Body $body
} Else {
Write-Host "Expected file '$($fullName)' found."
}
}
Open in new window