-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPOReportHelper.psm1
63 lines (59 loc) · 2.04 KB
/
GPOReportHelper.psm1
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
51
52
53
54
55
56
57
58
59
60
61
62
63
# https://gist.github.com/joegasper/3fafa5750261d96d5e6edf112414ae18
# Updated ConvertFrom-DN to support container objects
function ConvertFrom-DN {
[cmdletbinding()]
param(
[Parameter(Mandatory, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullOrEmpty()]
[string[]]$DistinguishedName
)
process {
foreach ($DN in $DistinguishedName) {
Write-Verbose $DN
$CanonNameSlug = ''
$DC = ''
foreach ( $item in ($DN.replace('\,', '~').split(','))) {
if ( $item -notmatch 'DC=') {
$CanonNameSlug = $item.Substring(3) + '/' + $CanonNameSlug
}
else {
$DC += $item.Replace('DC=', ''); $DC += '.'
}
}
$CanonicalName = $DC.Trim('.') + '/' + $CanonNameSlug.Replace('~', '\,').Trim('/')
[PSCustomObject]@{
'CanonicalName' = $CanonicalName;
}
}
}
}
function ConvertFrom-CanonicalUser {
[cmdletbinding()]
param(
[Parameter(Mandatory, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullOrEmpty()]
[string]$CanonicalName
)
process {
$obj = $CanonicalName.Split('/')
[string]$DN = 'CN=' + $obj[$obj.count - 1]
for ($i = $obj.count - 2; $i -ge 1; $i--) { $DN += ',OU=' + $obj[$i] }
$obj[0].split('.') | ForEach-Object { $DN += ',DC=' + $_ }
return $DN
}
}
function ConvertFrom-CanonicalOU {
[cmdletbinding()]
param(
[Parameter(Mandatory, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullOrEmpty()]
[string]$CanonicalName
)
process {
$obj = $CanonicalName.Split('/')
[string]$DN = 'OU=' + $obj[$obj.count - 1]
for ($i = $obj.count - 2; $i -ge 1; $i--) { $DN += ',OU=' + $obj[$i] }
$obj[0].split('.') | ForEach-Object { $DN += ',DC=' + $_ }
return $DN
}
}