Created
August 2, 2022 12:00
-
-
Save chris-bradbury/f354fa8e84d272ab1c039ad5c3d9ffc5 to your computer and use it in GitHub Desktop.
A quick powershell function to use Robocopy to delete a full directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RoboDelete{ | |
param ( | |
$Path | |
) | |
##-- generate a randomly named folder --## | |
$randomString = -join ((48..57) + (97..122) | Get-Random -Count 32 | % {[char]$_}) | |
##-- make the empty directory --## | |
New-Item -ItemType Directory -Path $randomString -Verbose | |
$emptyDirectory = Get-Item -Path $randomString -Force -Verbose | |
$emptyDirectory.Attributes = 'Hidden' | |
##-- robocopy delete the directory --## | |
Robocopy.exe $randomString $Path /MIR /MT:128 | |
##-- delete the empty directory --## | |
Remove-Item -Path $randomString -Force -Verbose -Recurse | |
##-- delete the now empty directory we were deleting --## | |
Remove-Item -Path $Path -Force -Verbose -Recurse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment