Skip to content

Instantly share code, notes, and snippets.

@SoulOfUniverse
Created July 13, 2021 19:12
Show Gist options
  • Save SoulOfUniverse/97d754ce1ff87a9e5d987e038cad6d9c to your computer and use it in GitHub Desktop.
Save SoulOfUniverse/97d754ce1ff87a9e5d987e038cad6d9c to your computer and use it in GitHub Desktop.
Powershell Cleaning Directory
param
(
[ValidateScript( {Test-Path $_})]
[string]$path,
[switch] $force = $false
)
if (Test-Path $path) {
if ($path -like "*C:*" -and -not $force) {
Write-Error "$path is system path cannot be used"
}
else {
Write-Host "Cleaning $path directory" -ForegroundColor Green
Remove-Item -Path $path\* -Recurse
Write-Host "$path directory is now empty" -ForegroundColor Green
}
}
else {
Write-Error "$path path is invalid"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment