Public/Get-StringHash.ps1

Function Get-StringHash{
  <#
      .SYNOPSIS
      This is used to generate a unique hash string from an ordinary string value.
 
      .NOTES
      Author: Tyson Paul
      Date: 2018.05.30
      Blog: https://monitoringguys.com/
      History:
      Adapted from http://jongurgul.com/blog/get-stringhash-get-filehash/
  #>


  [CmdletBinding(DefaultParameterSetName='Parameter Set 1',
      SupportsShouldProcess=$true,
      PositionalBinding=$false,
      HelpUri = 'https://monitoringguys.com/',
  ConfirmImpact='Medium')]

  Param (
    [Parameter(Mandatory=$true,
        ValueFromPipeline=$false,
        ValueFromPipelineByPropertyName=$false,
        ValueFromRemainingArguments=$false,
        Position=0,
    ParameterSetName='Parameter Set 1')]
    [String] $String,

    [Parameter(Mandatory=$false,
        ValueFromPipeline=$false,
        ValueFromPipelineByPropertyName=$false,
        ValueFromRemainingArguments=$false,
        Position=1,
    ParameterSetName='Parameter Set 1')]
    [ValidateSet("SHA", "SHA1", "MD5", "SHA256", "SHA384", "SHA512","MACTripleDES","RIPEMD160")]
    $Algorithm = "MACTripleDES" #SHA1 is default. https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.hashalgorithm.create?view=netframework-4.8
  )

  $StringBuilder = New-Object System.Text.StringBuilder
  [System.Security.Cryptography.HashAlgorithm]::Create($Algorithm).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|ForEach-Object{
    [Void]$StringBuilder.Append($_.ToString("x2"))
  }
  $StringBuilder.ToString()
}