Categories
PowerShell Scripting

PowerShell Hex 2 Ascii Function

Function to convert a HEX value to Ascii. Example:

>fnHex2Ascii -HexValue “00000000”

function fnHex2Ascii()
{
  param (
    [string]$HexString
	)
  
  Clear-Variable -Name sAscii -ErrorAction SilentlyContinue
  $HexString -Split '(.{2})' | %{ if ($_ -ne "") { $sAscii+=[CHAR]([CONVERT]::toint16($_,16)) } }

  # Return metadata and body...
  return $sAscii 
}