POwershell Slet mapper ældre end x dage, undtaget følgene mapper!
Hej scriptet kopper fint over mapperner i exclude filen men når den del var på plads så ignorere den at de skal være over 2 dage gamle... hvad er der gået galt?# Compatibility: PS v2.0 and newer.
$limit = (Get-Date).AddDays(-2)
$path = "C:\Users"
$ignore = Get-Content "c:\xxx\BlackListedFolders.txt"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.LastwriteTime -lt $limit } | Select-String -SimpleMatch -Pattern $ignore -NotMatch | Select-Object -ExpandProperty Line | Remove-Item -Force
# Delete any empty directories left behind after deleting the old files.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Select-String -SimpleMatch -Pattern $ignore -NotMatch | Select-Object -ExpandProperty Line | Remove-Item -Force -Recurse
# End of script