-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTo-sthSID.ps1
More file actions
40 lines (35 loc) · 888 Bytes
/
ConvertTo-sthSID.ps1
File metadata and controls
40 lines (35 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.externalhelp sthLDAPTools.psm1-Help.xml
#>
function ConvertTo-sthSID
{
[CmdletBinding()]
Param(
# User or Computer object's objectSID property in the byte array form.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$ByteArray
)
begin
{
$Stream = @()
}
process
{
foreach ($Byte in $ByteArray)
{
$Stream += $Byte
}
}
end
{
# Revision and IdentifierAuthority
$Result = "S-{0}-{1}" -f $Stream[0], $Stream[7]
# SubAuthority
for ($i = 0; $i -lt $Stream[1]; $i++)
{
$off = $i * 4
$Result = "$Result-{0}" -f $([uint32]$Stream[8 + $off] -bor ([uint32]$Stream[9 + $off] -shl 8) -bor ([uint32]$Stream[10 + $off] -shl 16) -bor ([uint32]$Stream[11 + $off] -shl 24))
}
return $Result
}
}