Kansa icon indicating copy to clipboard operation
Kansa copied to clipboard

get-filehashes module foreach error

Open 1amr00t opened this issue 8 years ago • 8 comments

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!

1amr00t avatar Oct 25 '16 20:10 1amr00t

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.

jt-msft avatar Oct 25 '16 20:10 jt-msft

Changing the -gt 2.0 condition to -gt 8.0 returned the same error.

1amr00t avatar Oct 25 '16 21:10 1amr00t

Thanks. I'll dive into it some more.

jt-msft avatar Oct 25 '16 22:10 jt-msft

I get the same error on the following modules:

Get-FileHashes Get-FilesByHash Get-FilesByHashes

mattfrancois25 avatar Feb 17 '17 14:02 mattfrancois25

@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.

athegist avatar Oct 14 '17 04:10 athegist

Why isn't $(Get-FileHash $File -Algorithm SHA256).Hash used instead?

slw07g avatar Nov 09 '17 15:11 slw07g

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.

athegist avatar Nov 11 '17 19:11 athegist

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.

Skwerl23 avatar Aug 16 '19 22:08 Skwerl23