PoshCode Archive  Artifact [a1d1c8c90d]

Artifact a1d1c8c90d14f3ae4e965a8b2687296f744526d62b93b914d32a2acbece41224:

  • File ConvertTo-Hex.ps1 — part of check-in [e72cca7ab8] at 2018-06-10 14:21:38 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: 1067)

# 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: 6838
# x-archived: 2017-04-14T18:09:27
# x-published: 2017-04-12T13:02:00
#
# 010500000000000515000000BB0B4815C33A022074381B7409050000
#
# 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 ''