Created
December 14, 2021 21:14
-
-
Save alexverboon/0a7a32b8f1267f4a9ac34b5e1c5b1ba5 to your computer and use it in GitHub Desktop.
PowerShell script to find log4j-core.jar files
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
Function Get-log4files(){ | |
$Drives = Get-PSDrive | Select-Object -ExpandProperty 'Name' | Select-String -Pattern '^[a-e]$' | |
$FileInfo = [System.Collections.ArrayList]::new() | |
$Filetypes = @("*.jar") | |
ForEach($DriveLetter in $Drives) | |
{ | |
$Drive = "$DriveLetter" + ":\" | |
$Log4Files = Get-ChildItem -Path $Drive -Filter "*log4j-core*" -Include $Filetypes -Recurse -File -ErrorAction SilentlyContinue | Select-Object FullName | |
Foreach($file in $Log4Files) | |
{ | |
if(-not [string]::IsNullOrEmpty($file.FullName)) | |
{ | |
$Result = [PSCustomObject]@{ | |
D = $env:ComputerName | |
FH = (Get-FileHash -Path $file.FullName -Algorithm SHA256).Hash | |
F = $file.FullName | |
} | |
} | |
[void]$FileInfo.Add($Result) | |
} | |
} | |
$FileInfo | |
} | |
Get-log4files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this script built to output results regardless if files are found or NOT? I can't tell when I look at each of your lines. And I've ran the script on a test machine with no output/results file to be found.