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?