I'm writing a script to collect all file hashes in the C: drive but doesn't grab everything. Anyone have any ideas? I tried a mix of things.
gci -Path C:\ -Recurse | Get-FileHash -Algorithm MD5 | Out-File C:\test.txt
Since you're calculating file hashes, make Get-ChildItem
return files only, using the -File
switch.
In order to also process hidden files, additionally use the -Force
switch.
You must run the command with elevation (as admin) to ensure that you have access to all files, though it is still possible for access to be denied to certain directories and files.
C:\Users\jdoe\Cookies
) that exist for backward compatibility only; however, you can ignore those, because they simply point to other directories that can be accessed.Get-ChildItem
in this scenario would also ignore any NTFS reparse points that point to other drives or directories (junctions, symbolic links, mount points) even if they are accessible - which is probably what you want.-ea SilentlyContinue -ev errs
(short for: -ErrorAction SilentlyContinue -ErrorVariable errs
), you can examine array $errs
afterwards to see which files, specifically, could not be accessed.# Examine $errs afterwards to see which paths couldn't be accessed.
Get-ChildItem C:\ -Recurse -File -Force -ea SilentlyContinue -ev errs |
Get-FileHash -Algorithm MD5 |
Out-File C:\test.txt
Note: The Out-File
cmdlet saves the for-display representation of the command's output to a file, which isn't designed for further programmatic processing.
To save a representation that is suitable for subsequent programmatic processing, use a cmdlet such as Export-Csv
.