Compare commits

...

4 Commits

Author SHA1 Message Date
1b45ccef74 pull apps from registry and show their size 2024-06-07 17:52:30 -04:00
b67f1c8c9a fix formatting and messaging 2024-06-07 17:42:40 -04:00
2e093f6856 add example output 2024-06-07 17:01:34 -04:00
14d38a1cbd fix int overflow for large recoveries 2024-06-07 16:58:42 -04:00
3 changed files with 13727 additions and 7 deletions

32
windows/appchk.ps1 Normal file
View File

@ -0,0 +1,32 @@
# Define the registry paths for 32-bit and 64-bit applications
$registryPaths = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
)
# Initialize an array to store application information
$applications = @()
# Loop through each registry path
foreach ($registryPath in $registryPaths) {
# Get the registry keys for each application
$keys = Get-ChildItem -Path $registryPath
foreach ($key in $keys) {
# Get the application properties
$app = Get-ItemProperty -Path $key.PSPath
# Add the application information to the array
$applications += [PSCustomObject]@{
Name = $app.DisplayName
Version = $app.DisplayVersion
Publisher = $app.Publisher
InstallDate = $app.InstallDate
Size = $app.EstimatedSize
}
}
}
# Filter out applications with no name
$applications = $applications | Where-Object { $_.Name -ne $null }
# Display the applications
$applications | Select-Object Name, Version, Publisher, InstallDate, Size | Format-Table -AutoSize

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ function ShowSizes() {
[string]$description, [string]$description,
[Parameter(Mandatory = $true, Position = 1)] [Parameter(Mandatory = $true, Position = 1)]
[int]$sizeInBytes [Int64]$sizeInBytes
) )
# Convert the size to kilobytes (KB) # Convert the size to kilobytes (KB)
@ -189,7 +189,6 @@ function Get-Duplicates {
if ($dup_files.Count -gt 1) { if ($dup_files.Count -gt 1) {
$dups_hash[$entry.key] = $dup_files | Sort-Object -Property Creation -Descending $dups_hash[$entry.key] = $dup_files | Sort-Object -Property Creation -Descending
#$dup_files = $dups_hash[$entry.key]
} }
} }
$dups_hash $dups_hash
@ -203,7 +202,7 @@ function Show-Duplicates {
) )
$num_dups = 0 $num_dups = 0
$total_dup_size = 0 $total_dup_size = 0.0
foreach ($entry in $files.GetEnumerator()) { foreach ($entry in $files.GetEnumerator()) {
$dup_files = $entry.Value $dup_files = $entry.Value
@ -214,14 +213,18 @@ function Show-Duplicates {
} }
Write-Output "" Write-Output ""
Write-Output "Found duplicate $($num_dups): $($entry.Key)" Write-Output "Found duplicate $(Format-NumberWithCommas $num_dups): $($entry.Key)"
for ($i = 0; $i -lt $dup_files.Count; $i++) { for ($i = 0; $i -lt $dup_files.Count; $i++) {
# only count disk space of removals
if ($i -gt 0) {
$total_dup_size += $dup_files[$i].Size $total_dup_size += $dup_files[$i].Size
}
Write-Output "$($hash_num): $($dup_files[$i].ToString())" Write-Output "$($hash_num): $($dup_files[$i].ToString())"
} }
} }
Write-Output "" Write-Output ""
Write-Output "Found $num_dups duplicate file hashes." Write-Output "Found $(Format-NumberWithCommas $num_dups) duplicate file hashes."
ShowSizes "Duplicate Files Size" $total_dup_size ShowSizes "Duplicate Files Size" $total_dup_size
} }
@ -282,7 +285,7 @@ function DeleteDuplicateFile {
Write-Output "Deleting File: $($File.Name) $(Format-NumberWithCommas $File.fileSizeInKB) KB" Write-Output "Deleting File: $($File.Name) $(Format-NumberWithCommas $File.fileSizeInKB) KB"
BackupDuplicateFile -file $File -backupDirectory $backup_dir BackupDuplicateFile -file $File -backupDirectory $backup_dir
# Force delete a read-only or protected file # Force delete a read-only or protected file
Write-Output " ... would deleting: $($File.FullName)" Write-Output " ... deleting: $($File.FullName)"
Remove-Item -Path $File.FullName -Force Remove-Item -Path $File.FullName -Force
Write-Output " - removed from: $($File.Directory)" Write-Output " - removed from: $($File.Directory)"
} }