Skip to content

Instantly share code, notes, and snippets.

@chris-bradbury
Created August 2, 2022 12:00
Show Gist options
  • Save chris-bradbury/f354fa8e84d272ab1c039ad5c3d9ffc5 to your computer and use it in GitHub Desktop.
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.
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