logo powershell

Prullenbak legen via powershell

Powershell ten behoeve van het legen van alle recycle.bin mappen op alle aanwezige schijven.

 ForEach ($Drive in Get-PSDrive -PSProvider FileSystem) {
     $Path = $Drive.Name + ‘:\$RECYCLE.BIN’
     "Testing {0}" -f $path
     $files = Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue 
     foreach ($f in $files) {
         "{0} - {1}" -f $f.name, $f.lastwritetime
         if ( $f.LastWriteTime -lt (Get-Date).AddDays(-7)) {
             "   Delete the above file."
             $f | Remove-Item -Recurse -Force -whatif 
         }
     }
 }