Create a SHA1 hash in PowerShell

There is not that much to say. Attached is a Script that generates a SHA1 Hash from a String.

Why for me?

We have several Servers they are storing files in a specified format on different folders. I should write a Powershell Script who grab the content of each file and save the string back.

For testing purpose, I stored the File first in two local folders. One is called ArchivOriginal and ArchivEdited. For each filename I would like to give them a traceable name like server_share_folder1_folder2.txt. But the folder is deep nested some paths have more than 248 characters. :-(

Here you can find the script which was very handy for me, I hope it is also the same for you.

.\Get-SHA1HashFromString.ps1 "//server/share/folder1/folder3.txt"

That it’s not enough - because the SHA1 produces char who are not allowed for Windows. Here is my way to cleanup that.

((((((((.\Get-SHA1HashFromString.ps1 "//server/share/folder1/folder3.txt") -replace "/", "_slash_") -replace "\\", "_backslash_") -replace ":", "_doublepoint_") -replace "\*","_star_") -replace "\?", "_question_") -replace "\<", "_lt_") -replace "\>","_gt_") -replace "\|", "_strike_"

If you also find this script useful, you can download it here.


Comments

comments powered by Disqus