Skip to content

Commit

Permalink
Merge pull request #751 from Ana06/desktop-hidden-files
Browse files Browse the repository at this point in the history
Improve files deleted in VM-Remove-DesktopFiles/VM-Clean-Up
  • Loading branch information
Ana06 authored Nov 23, 2023
2 parents d3090ff + 4ce4958 commit c3bf82d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20231116</version>
<version>0.0.0.20231123</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
11 changes: 6 additions & 5 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public class Shell {


# Usage example:
# VM-Remove-DesktopFiles -excludeFolders "PS_Transcripts", ${Env:TOOL_LIST_DIR}, "fakenet_logs" -excludeFiles "example.txt", "important.doc"
# VM-Remove-DesktopFiles -excludeFolders ${Env:TOOL_LIST_DIR}, "fakenet_logs" -excludeFiles "example.txt", "important.doc"
# The function is run against both the Current User and 'Public' desktops due to some cases where desktop icons showing on
# Current user Desktop that are only located in Public/Desktop.
function VM-Remove-DesktopFiles {
Expand All @@ -1257,8 +1257,8 @@ function VM-Remove-DesktopFiles {
[Parameter(Mandatory=$false)]
[string[]]$excludeFiles
)
# Ensure that the "PS_Transcripts" and "fakenet_logs" folders, as well as the Tools Folder (if located on the desktop) are not to be deleted.
$defaultExcludedFolders = @("PS_Transcripts", ${Env:TOOL_LIST_DIR}, "fakenet_logs")
# Ensure that the "fakenet_logs" folders, as well as the Tools Folder (if located on the desktop) are not to be deleted.
$defaultExcludedFolders = @(${Env:TOOL_LIST_DIR}, "fakenet_logs")
$defaultExcludedFiles = @("MICROSOFT Windows 10 License Terms.txt")
$excludeFolders = $excludeFolders + $defaultExcludedFolders
$excludeFiles = $excludeFiles + $defaultExcludedFiles
Expand All @@ -1267,7 +1267,8 @@ function VM-Remove-DesktopFiles {
[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::CommonDesktopDirectory) # Public desktop
)
foreach ($userDesktopPath in $userAccounts) {
Get-ChildItem -Path $userDesktopPath | ForEach-Object {
# Use -Force to get hidden files (such as desktop.ini)
Get-ChildItem -Path $userDesktopPath -Force | ForEach-Object {
$item = $_
try{
if ($item.PSIsContainer -and ($item.Name -notin $excludeFolders -and $item.FullName -notin $excludeFolders)) {
Expand Down Expand Up @@ -1332,4 +1333,4 @@ function VM-Clean-Up {

Write-Host "[+] Clearing up free space. This may take a few minutes..." -ForegroundColor Green
VM-Clear-FreeSpace
}
}

0 comments on commit c3bf82d

Please sign in to comment.