-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheck-ADHybridSCP.ps1
35 lines (31 loc) · 1.16 KB
/
Check-ADHybridSCP.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
param (
[string]
$domainDN = "DC=<Domain>,DC=Lab"
)
##### Variables #####
$drcPath = "CN=Device Registration Configuration,CN=Services,CN=Configuration,$domainDN"
$tenanNameREX = [Regex]::new("(?<=azureADName:)([a-zA-Z0-9\.]*)")
$tenanidREX = [Regex]::new("(?<=azureADId:)([a-zA-Z0-9\-]*)")
#Import the ActiveDirectory PowerShell Module
Import-Module ActiveDirectory
#Set Location to AD
Set-Location AD:
#Test if the Device Registration Configuration Exists, if it does set it to the current location
Switch(Test-Path -Path $drcPath) {
true {
Push-Location $drcPath
Get-ChildItem | ForEach-Object {
$_.DistinguishedName
[PSCustomObject]@{
tenantName = $tenanNameREX.Match((Get-ADObject $_.DistinguishedName -Properties Keywords).Keywords).Value
tenantID = $tenanidREX.Match((Get-ADObject $_.DistinguishedName -Properties Keywords).Keywords).Value
keywords = (Get-ADObject $_.DistinguishedName -Properties Keywords).Keywords
} | Format-Table -Wrap
}
Pop-Location
}
false {
Pop-Location
throw "$drcpath Does not exist"
}
}