Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.20250814</version>
<version>0.0.0.20251015</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
40 changes: 27 additions & 13 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1698,18 +1698,18 @@ function VM-Remove-DesktopFiles {
)
foreach ($userDesktopPath in $userAccounts) {
# Use -Force to get hidden files (such as desktop.ini)
VM-Write-Log "INFO" "Deleting the files and folders under $($userDesktopPath)"
Get-ChildItem -Path $userDesktopPath -Force | ForEach-Object {
$item = $_
if ($item.PSIsContainer -and ($item.Name -notin $excludeFolders -and $item.FullName -notin $excludeFolders)) {
VM-Write-Log "INFO" "Deleting folder: $($item.FullName)"
Remove-Item -Path $item.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
elseif ($item.PSIsContainer -eq $false -and ($item.Name -notin $excludeFiles -and $item.FullName -notin $excludeFiles)) {
VM-Write-Log "INFO" "Deleting file: $($item.FullName)"
Remove-Item -Path $item.FullName -Force -ErrorAction SilentlyContinue
}
if(!$?){
VM-Write-Log "ERROR" "`tFailed to delete"
# Verbosely logging the errors since it's very unlikely to happen
VM-Write-Log "ERROR" "`tFailed to delete $($item.FullName)"
}
}
}
Expand All @@ -1721,14 +1721,29 @@ function VM-Clear-TempAndCache {
$localAppDataPath = [System.Environment]::GetFolderPath('LocalApplicationData')
$commonAppDataPath = [System.Environment]::GetFolderPath('CommonApplicationData')
$nugetCache = Join-Path $localAppDataPath 'NuGet\cache'
$packageCache1 = Join-Path $localAppDataPath 'Package` Cache'
$packageCache2 = Join-Path $commonAppDataPath 'Package` Cache'
$packageCache1 = Join-Path $localAppDataPath 'Package Cache'
$packageCache2 = Join-Path $commonAppDataPath 'Package Cache'

$command1 = 'cmd /c del /Q /S ' + $temp
$command2 = 'cmd /c rmdir /Q /S ' + $chocolatey + ' ' + $nugetCache + ' ' + $packageCache1 + ' ' + $packageCache2
VM-Write-Log "INFO" "Deleting the files under $($temp)"
Get-ChildItem -Path $temp -Force -Recurse -File | Remove-Item -Force -ErrorAction SilentlyContinue

Invoke-Expression $command1
Invoke-Expression $command2
foreach ($folder in @(
$chocolatey, $nugetCache, $packageCache1, $packageCache2
)) {
VM-Write-Log "INFO" "Deleting the folder $($folder)"
Remove-Item -Path $folder -Force -Recurse -ErrorAction SilentlyContinue
}
}

function VM-Disk-Cleanup {
VM-Write-Log "INFO" "Performing Disk Cleanup."
$cleanmgrPath = Get-Command -Name "cleanmgr.exe" -ErrorAction SilentlyContinue
if ($cleanmgrPath) {
Invoke-Expression 'cmd /c cleanmgr /AUTOCLEAN'
}
else {
VM-Write-Log "ERROR" "`tcleanmgr not found."
}
}

# SDelete can take a bit of time (~2+ mins) and requires sysinternals to be installed
Expand Down Expand Up @@ -1763,8 +1778,7 @@ function VM-Clean-Up {
Clear-RecycleBin -Force -ErrorAction Continue

Write-Host "[+] Running Disk Cleanup..." -ForegroundColor Green
VM-Write-Log "INFO" "Performing Disk Cleanup."
Invoke-Expression 'cmd /c cleanmgr.exe /AUTOCLEAN'
VM-Disk-Cleanup

Write-Host "[+] Clearing up free space. This may take a few minutes..." -ForegroundColor Green
VM-Clear-FreeSpace
Expand Down Expand Up @@ -1929,8 +1943,8 @@ function VM-Set-Legal-Notice {
[string[]]$legalnoticetext
)
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
New-ItemProperty -Path $RegistryPath -Name legalnoticecaption -Value "Terms and Conditions" -Force
New-ItemProperty -Path $RegistryPath -Name legalnoticetext -Value $legalnoticetext -Force
New-ItemProperty -Path $RegistryPath -Name legalnoticecaption -Value "Terms and Conditions" -Force | Out-Null
New-ItemProperty -Path $RegistryPath -Name legalnoticetext -Value $legalnoticetext -Force | Out-Null
}

# Converts image file to .ico needed for file icons
Expand Down
Loading