Created
July 13, 2021 19:12
-
-
Save SoulOfUniverse/97d754ce1ff87a9e5d987e038cad6d9c to your computer and use it in GitHub Desktop.
Powershell Cleaning 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
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