Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Quickly delete large folders with PS

$
0
0

I have a script right now that goes through and deletes a list of directories (old users home directories).  It does this just fine and here is a code sample:

Get-Content $UsersFile | ForEach-Object {
    $pathcheck = Test-Path "$basePath\$_"
    If ($pathcheck -eq $false){
        Write-Host "'$basePath\$_' could not be found"
        LogWrite "'$basePath\$_' could not be found"
    } Else {
        Remove-Item "$basePath\$_" -Recurse -Force -Verbose
        Write-Host "$ScriptContext has removed '$basePath\$_'"
        LogWrite "$ScriptContext has removed '$basePath\$_'"
    }
}

As you can see I'm using "Remove-Item <Path> -Recurse -Force -Verbose" to delete the targeted folder and all of it's contents.  While that is working, it seems to take longer to delete a single large folder than if I were to simply right-click on that large folder and say delete permanently.  Is there a faster way to completely delete a directory and all of its contents?

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>