Script: *remove-dir.ps1* ======================== This PowerShell script removes the given directory tree recursively. NOTE: Use with care! This cannot be undone! Parameters ---------- ```powershell PS> ./remove-dir.ps1 [[-pathToDir] ] [] -pathToDir Specifies the file path to the directory tree Required? false Position? 1 Default value Accept pipeline input? false Aliases Accept wildcard characters? false [] This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. ``` Example ------- ```powershell PS> ./remove-dir.ps1 C:\Temp ⏳ Removing directory 'C:\Temp', please wait..." ✅ Directory C:\Temp\ removed (took 9s). ``` Notes ----- Author: Markus Fleschutz | License: CC0 Related Links ------------- https://github.com/fleschutz/PowerShell Script Content -------------- ```powershell <# .SYNOPSIS Removes a directory .DESCRIPTION This PowerShell script removes the given directory tree recursively. NOTE: Use with care! This cannot be undone! .PARAMETER pathToDir Specifies the file path to the directory tree .EXAMPLE PS> ./remove-dir.ps1 C:\Temp ⏳ Removing directory 'C:\Temp', please wait..." ✅ Directory C:\Temp\ removed (took 9s). .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> param([string]$pathToDir = "") try { if ($pathToDir -eq "" ) { $pathToDir = Read-Host "Enter the file path to the obsolete directory" } $stopWatch = [system.diagnostics.stopwatch]::startNew() if (!(Test-Path "$pathToDir" -pathType container)) { throw "Cannot access directory '$pathToDir'" } "⏳ Removing directory '$pathToDir', please wait..." Remove-Item -force -recurse -confirm:$false $pathToDir if ($lastExitCode -ne 0) { throw "'Remove-Item' failed with exit code $lastExitCode" } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds "✅ Directory $pathToDir removed (took $($elapsed)s)." exit 0 # success } catch { "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } ``` *(page generated by convert-ps2md.ps1 as of 08/07/2025 16:01:07)*