Lidt Powershell til at ryde op i mapper som ikke har haft file ændringer i x antal dage.
med mulighed hvor at definere antallet af dage via Registry value
#Days where nochanges have been in the folder. $Days = (get-date).AddDays(-7) # Time is used for Script test $Time = (get-date).AddMinutes(-10) $key = 'HKLM:\SOFTWARE\Policies\nethelp\Outlook' $key = 'HKLM:\SOFTWARE\nethelp\Outlook' $key = 'HKCU:\SOFTWARE\nethelp\Outlook' if(test-path $key) { $DaysTemp = (Get-ItemProperty -Path $key -Name DirAge).DirAge if ($DaysTemp) { $Days = (get-date).AddDays($DaysTemp) Write-host "Using Registry Value Calculated time" Write-Host "Compair date : " $Days } else { Write-host "Using deault Calculated time" Write-Host "Compair date : " $Days } } #Get-ChildItem C:\outlook | where-object {$_.lastwritetime -le $Days} $CleanupFolders = Get-ChildItem C:\outlook foreach($Userdir in $CleanupFolders) { Write-Host "Looking for changed Files in " $Userdir.FullName #$obj = Get-ChildItem $Userdir.FullName -Recurse | where-object {$_.lastwritetime -ge $Time} $obj = Get-ChildItem $Userdir.FullName -Recurse | where-object {$_.lastwritetime -ge $days} if ($obj) { Write-Host " Any File changed since " $time $obj } else { $obj Write-Host "Dir has not been used within defined time periode" $Days Write-Host "Removing Dir : " $Userdir.FullName # Remove-Item $Userdir.FullName -Recurse -Force } }