Get-Ryan

[Powershell] Convert-ByteArraytoHex

Feb 1st, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Convert-ByteArrayToHex {
  2.  
  3.     [cmdletbinding()]
  4.  
  5.     param(
  6.         [parameter(Mandatory=$true)]
  7.         [Byte[]]
  8.         $Bytes
  9.     )
  10.  
  11.     $HexString = [System.Text.StringBuilder]::new($Bytes.Length * 2)
  12.  
  13.     ForEach($byte in $Bytes){
  14.         $HexString.AppendFormat("{0:x2}", $byte) | Out-Null
  15.     }
  16.  
  17.     $HexString.ToString()
  18. }
Advertisement
Add Comment
Please, Sign In to add comment