diff --git a/packages/common.vm/tools/vm.common/vm.common.psm1 b/packages/common.vm/tools/vm.common/vm.common.psm1 index e76faf8d5..ecbf6dfff 100755 --- a/packages/common.vm/tools/vm.common/vm.common.psm1 +++ b/packages/common.vm/tools/vm.common/vm.common.psm1 @@ -1245,6 +1245,19 @@ public class Shell { } } +# Remove a directory and if not possible as many of its subfolder and files as possible +function VM-Remove-Dir { + param ( + [Parameter(Mandatory=$true)] + [string[]]$item + ) + Remove-Item -Path $item -Recurse -Force -ErrorAction Continue + if (!$? -and $item.PSIsContainer) { + Get-ChildItem -Path $item -Force | ForEach-Object { + VM-Remove-Dir $item + } + } +} # Usage example: # VM-Remove-DesktopFiles -excludeFolders "PS_Transcripts", ${Env:TOOL_LIST_DIR}, "fakenet_logs" -excludeFiles "example.txt", "important.doc" @@ -1284,6 +1297,9 @@ function VM-Remove-DesktopFiles { } } } + + # Remove as much of PS_Transcripts as possible + VM-Remove-Dir "PS_Transcripts" } function VM-Clear-TempAndCache {