Param(
        [Parameter(Mandatory=$true)][ValidateScript({Test-Path -Path $_ -PathType Container})][String]$Path,
        [Parameter(Mandatory=$true)][ValidateScript({Test-Path -Path $_ -PathType Container})][String]$TemporaryPath
)

function Remove-Folder([String]$Path, [String]$TemporaryPath) {
        if (([IO.Directory]::Exists($Path)) -and ([IO.Directory]::Exists($TemporaryPath))) {
                foreach ($Item in [IO.directory]::EnumerateFileSystemEntries($Path)) {
                        $ItemPath = [IO.Path]::Combine($Path, $Item)
                        if ([IO.Directory]::Exists($ItemPath)) {
                                Remove-Folder -Path $ItemPath -TemporaryPath $TemporaryPath
                        } else {
                                $TemporaryItemPath = [IO.Path]::Combine($TemporaryPath, [IO.Path]::GetRandomFileName())
                                try {
                                        [IO.File]::Move($ItemPath, $TemporaryItemPath)
                                        [IO.File]::Delete($TemporaryItemPath)
                                } catch {}
                        }
                }
                $TemporaryItemPath = [IO.Path]::Combine($TemporaryPath, [IO.Path]::GetRandomFileName())
                try {
                        [IO.Directory]::Move($Path, $TemporaryItemPath)
                        [IO.Directory]::Delete($TemporaryItemPath)
                } catch {}
        }
}

Remove-Folder -Path $Path -TemporaryPath $TemporaryPath
