Public/Remove-Folder.ps1
# Remove-Folder C:\src\Beispiele @("node_modules", "npm-cache") function Remove-Folder { [CmdletBinding(SupportsShouldProcess = $True)] Param( [string]$Path = $pwd, [Parameter(Mandatory = $true)] [string[]]$Names, [Parameter()][switch]$Disable ) $childs = Get-ChildItem $Path foreach ($item in $childs) { if ($item -is [System.IO.DirectoryInfo]) { $curDir = Join-Path $Path $item # $_ is the piped item value of $Names if ($Names | Where-Object { $item.Name -eq $_ }) { if ($PSCmdlet.ShouldProcess($item)) { Remove-Item -Path "$curDir" -Recurse -Force Write-Host "$curDir" } } else { # check subfolders Remove-Folder "$curDir" $Names } } } } |