Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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