-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertFrom-sthSID.ps1
More file actions
50 lines (41 loc) · 1.17 KB
/
ConvertFrom-sthSID.ps1
File metadata and controls
50 lines (41 loc) · 1.17 KB
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
41
42
43
44
45
46
47
48
49
50
<#
.externalhelp sthLDAPTools.psm1-Help.xml
#>
function ConvertFrom-sthSID
{
[CmdletBinding()]
[OutputType([System.Byte])]
Param(
# SID in string form.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]
$SID
)
process
{
foreach ($s in $SID)
{
$SIDSplitted = $s -split '-' | Select-Object -Skip 1
$Result = @()
# Revision
$Result += [byte]$SIDSplitted[0]
# SubAuthorityCount
$Result += [byte]$($SIDSplitted.Count - 2)
# IdentifierAuthority
for ($i = 0; $i -lt 5; $i++)
{
$Result += [byte]0
}
$Result += [byte]$SIDSplitted[1]
# SubAuthority
for ($i = 2; $i -lt $($SIDSplitted.Count); $i++)
{
$Result += [byte]$($SIDSplitted[$i] -band 255)
$Result += [byte]$(($SIDSplitted[$i] -shr 8) -band 255)
$Result += [byte]$(($SIDSplitted[$i] -shr 16) -band 255)
$Result += [byte]$(($SIDSplitted[$i] -shr 24) -band 255)
}
$Result
}
}
}