From c0c84d43861ecbb15dafed6ff6ce29f304d4314b Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Thu, 4 Jan 2024 17:57:36 +0100 Subject: [PATCH] [common.vm] Remove PS_Transcripts in VM-Clean-Up Remove as much of `PS_Transcripts` as possible in `VM-Remove-DesktopFiles` (called by `VM-Clean-Up`). --- .../common.vm/tools/vm.common/vm.common.psm1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 {