Last active
November 14, 2023 07:42
-
-
Save DonovanDiamond/2ee649709a94941ccf95a95aef3406f5 to your computer and use it in GitHub Desktop.
NTFS Compressed or Encrypted File Scan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Scans all user profile directories recursively for Compressed or Encrypted files or folders | |
$Directory = "C:\Users\" | |
$users = Get-ChildItem -Directory -Path $Directory | |
$total = $users.Count | |
$i = 0 | |
ForEach ($user in $users) { | |
$i++ | |
Write-Progress -Activity "Scanned $i of $total" -Status "$user" -PercentComplete (($i/$total)*100) | |
Write-Host " - $Directory$user\" | |
if ($user.Name -eq "donotscan") { | |
} else { | |
$count = 0 | |
$skipped = 0 | |
$compressedFiles = @() | |
$encryptedFiles = @() | |
$files = Get-ChildItem -Path "$Directory$user\" -Recurse | | |
%{ | |
if ($_.Attributes -band [System.IO.FileAttributes]::Compressed) { | |
$covered = $false | |
foreach ($f in $compressedFiles) { | |
if ($_.FullName -like $f+"*") { | |
$covered = $true | |
} | |
} | |
if ($covered) { | |
$skipped++ | |
} else { | |
$compressedFiles += $_.FullName | |
} | |
} | |
if ($_.Attributes -band [System.IO.FileAttributes]::Encrypted) { | |
$covered = $false | |
foreach ($f in $encryptedFiles) { | |
if ($_.FullName -like $f+"*") { | |
$covered = $true | |
} | |
} | |
if ($covered) { | |
$skipped++ | |
} else { | |
$encryptedFiles += $_.FullName | |
} | |
} | |
$count++; | |
if ($count%1000 -eq 0) { | |
Write-Progress -Activity "Scanned $i of $total" -Status "$user - ($count) $($_.FullName)" -PercentComplete (($i/$total)*100) | |
} | |
} | |
if ($compressedFiles.Count -gt 0 -or $encryptedFiles.Count -gt 0) { | |
Write-Host "Skipped $skipped subfiles/subdirectories" | |
if ($compressedFiles.Count -gt 0) { | |
Write-Host "" | |
Write-Host "$user has Compressed Files:" | |
$compressedFiles | ForEach-Object { Write-Host $_ } | |
Write-Host "" | |
} | |
if ($encryptedFiles.Count -gt 0) { | |
Write-Host "" | |
Write-Host "$user has Encrypted Files:" | |
$encryptedFiles | ForEach-Object { Write-Host $_ } | |
Write-Host "" | |
} | |
pause | |
}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment