PoshCode Archive  Artifact [d7a6511a0e]

Artifact d7a6511a0e51a31574b326cf68ae5610475fe0a775eaa38f6d84d90ea71f35d0:

  • File ConvertTo-Hex.ps1 — part of check-in [d1c38df3fd] at 2018-06-10 13:39:07 on branch trunk — This scConvertTo-Hex S-1-5-21-357043131-537017027-1947940980-1289ript will convert a security identifier (SID) in string format to its hexadecimal equivalent. e.g. (user: S-1-5-21-2398571 size: 1046)

# encoding: ascii
# api: powershell
# title: ConvertTo-Hex
# description: This scConvertTo-Hex S-1-5-21-357043131-537017027-1947940980-1289ript will convert a security identifier (SID) in string format to its hexadecimal equivalent. e.g. 
# version: 0.1
# author: S-1-5-21-2398571
# license: CC0
# x-poshcode-id: 4289
# x-archived: 2013-07-11T00:00:22
# x-published: 2013-07-03T08:27:00
#
# 6b,00,68,00,69,00,6e,00,67,00,00,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 ''