Skip to content

Instantly share code, notes, and snippets.

@alexverboon
Created December 14, 2021 21:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexverboon/0a7a32b8f1267f4a9ac34b5e1c5b1ba5 to your computer and use it in GitHub Desktop.
Save alexverboon/0a7a32b8f1267f4a9ac34b5e1c5b1ba5 to your computer and use it in GitHub Desktop.
PowerShell script to find log4j-core.jar files
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
@g0nz01
Copy link

g0nz01 commented Dec 16, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment