Skip to content

Instantly share code, notes, and snippets.

@dlwyatt
Created May 7, 2015 00:21
Show Gist options
  • Save dlwyatt/370cbd42521d08db8652 to your computer and use it in GitHub Desktop.
Save dlwyatt/370cbd42521d08db8652 to your computer and use it in GitHub Desktop.
Parse CSVDE-style SID string
$funky = '010500000000000515000000AA7045F3F11474788C4A5F8AE9030000'
try
{
$bytes = [byte[]]@(
for ($i = 0; $i -lt $funky.Length - 1; $i += 2)
{
[byte]::Parse($funky.Substring($i, 2), [System.Globalization.NumberStyles]::AllowHexSpecifier)
}
)
$sid = New-Object System.Security.Principal.SecurityIdentifier($bytes, 0)
$sid.Value
}
catch
{
throw "String '$funky' is garbage."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment