-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet-AltSecIDMapping.ps1
45 lines (41 loc) · 1.44 KB
/
Get-AltSecIDMapping.ps1
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
function Get-AltSecIDMapping {
<# Example usage
Get-AltSecIDMapping -SearchBase "CN=Users,DC=dumpster,DC=fire"
<Output:>
CN=Administrator,CN=Users,DC=dumpster,DC=fire
X509:<S>DC=fire,DC=dumpster,CN=Users,CN=Andy3
X509:<S>DC=fire,DC=dumpster,CN=Users,CN=Andy2
X509:<S>DC=fire,DC=dumpster,CN=Users,CN=Andy
#>
param (
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0
)]
[string]$SearchBase,
[Parameter(
Mandatory = $false
)]
[switch]$ExcludeStrong = $false
)
$searcher = [adsisearcher]""
$searcher.SearchRoot = "LDAP://$SearchBase"
$searcher.Filter = "(objectClass=*)"
$searcher.PropertiesToLoad.AddRange(@("altSecurityIdentities", "distinguishedName"))
$results = $searcher.FindAll()
foreach ($result in $results) {
$altSecIdentities = $result.Properties["altSecurityIdentities"]
$selectedAltSecIdentities = $altSecIdentities | ? {
-not $ExcludeStrong `
-or ($_ -notmatch '^X509:<(SKI|SHA1-PUKEY)>' `
-and $_ -notmatch '^X509:<I>.*<SR>')
}
if ($selectedAltSecIdentities -ne $null) {
Write-Host "`r"
Write-Host $result.Properties["distinguishedName"]
$selectedAltSecIdentities | ForEach-Object { Write-Host $_ }
}
}
}