Kansa
Kansa copied to clipboard
get-filehashes module foreach error
Environment: PSv4 on target and source. Run as user with admin on both systems and with scripts "unblocked". Latest Kansa code.
Issue: When running the Get-FileHashes module against a single target host, I get the following error:
"Get-FileHashes reports error on COMPUTERNAME: "Missing opening '(' after keyword 'foreach'."
The command run is:
KANSAPATH\kansa.ps1 -Target COMPUTERNAME -ModulePath "KANSAPATH\Modules\Disk\Get-FileHashes.ps1 MD5,C:\Users\"
Thanks in advance!
Can you try changing the conditional in Get-FileHashes.ps1 on line 232 from -gt 2.0
to -gt 8.0
or some other value that will never be true? I think this is due to the -parallel
flag in that function, but this should let us know for sure.
Changing the -gt 2.0 condition to -gt 8.0 returned the same error.
Thanks. I'll dive into it some more.
I get the same error on the following modules:
Get-FileHashes Get-FilesByHash Get-FilesByHashes
@z4ns4tsu were you ever able to repro this? I need to try it in my lab, but the code clearly has a check for PS version and should work.
Why isn't $(Get-FileHash $File -Algorithm SHA256).Hash
used instead?
Because Get-FileHash isn't on every system with PowerShell, unfortunately. Not sure when that came in as a first order cmdlet, PSv4 maybe? There's still a huge install base of PSv2, sadly.
Windows 10 doesn't do md5 hashes. To fix this go through all the hashing scripts and change md5 to sha512 or sha1 where it calls it. Or remove the call.