PoshCode Archive  Artifact [8a9e6d25c3]

Artifact 8a9e6d25c37a7160b395694ab5c86e5a4edb354fcd559399c734e4b9a32c1859:

  • File ConvertTo-Hex.ps1 — part of check-in [01f6b59511] at 2018-06-10 14:15:53 on branch trunk — S-1-5-11 (user: S-1-5-21-2398571 size: 851)

# encoding: ascii
# api: powershell
# title: ConvertTo-Hex
# description: S-1-5-11
# version: 0.1
# author: S-1-5-21-2398571
# license: CC0
# x-poshcode-id: 6443
# x-archived: 2016-07-10T05:12:39
# x-published: 2016-07-08T14:06:00
#
#
# Ported from C# technique found here: http://forums.asp.net/p/1298956/2529558.aspx
param ( [string]$SidString )

# Create SID .NET object using SID string provided
$sid = New-Object system.Security.Principal.SecurityIdentifier $sidstring

# Create a byte array of the proper length
$sidBytes = New-Object byte[] $sid.BinaryLength

#Convert to bytes
$sid.GetBinaryForm( $sidBytes, 0 )

# Iterate through bytes, converting each to the hexidecimal equivalent
$hexArr = $sidBytes | ForEach-Object { $_.ToString("X2") }

# Join the hex array into a single string for output
$hexArr -join ''