Last active
November 17, 2018 21:37
-
-
Save darrenjrobinson/5abe9271b325afb1e7c3a4eb448cf158 to your computer and use it in GitHub Desktop.
Generate Granfeldt PowerShell Management Agent Schema File - AAD User. Supporting blog post can be located here https://blog.darrenjrobinson.com/automate-the-generation-of-a-granfeldt-powershell-management-agent-schema-definition-file/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install-Module -Name AzureAD | |
Import-Module -Name AzureAD | |
# Connect and get a user to model the schema off | |
Connect-AzureAD | |
$object = Get-AzureADUser -ObjectId "user@domain.com.au" | |
$Attributes = $object | Get-Member -MemberType Property | |
$schema = @() | |
foreach ($attr in $Attributes) { | |
$d = $null # attr definition | |
$type = $null # attr type | |
$d = $attr.Definition.Split(" ") | |
if ($attr.Definition.StartsWith("string $($attr.Name)")) {$type = "string"} | |
if ($d[0] -eq "System.Nullable[bool]") {$type = "boolean"} | |
if ($d[0] -eq "System.Nullable[datetime]") {$type = "datetime"} | |
if ($d[0].StartsWith("System.Collections.Generic.List")) {$type = "multivalue"} | |
if ($d[0].StartsWith("System.Collections.Generic.Dictionary")) {$type = "multivalue"} | |
switch ($type) { | |
"string" {$schema += "$($d[1])|$($d[0])`" -Value `"string" + "`""} | |
"boolean" {$schema += "$($d[1])|boolean`" -Value `$true"} | |
"datetime" {$schema += "$($d[1])|string`" -Value `"string`""} | |
"multivalue" {$schema += "$($d[$d.Length-2])|String[]`" -Value (`"`",`"`")"} | |
} | |
} | |
# Generate Output Schema.ps1 | |
$output = @() | |
$output += "`$obj = New-Object -Type PSCustomObject" | |
$output += "`$obj | Add-Member -Type NoteProperty -Name `"Anchor-YourAnchorATTR|String`" -Value `"`"" | |
$output += "`$obj | Add-Member -Type NoteProperty -Name `"objectClass|String`" -Value `"YourObjectClass`"" | |
foreach ($obj in $schema) { | |
$output += "`$obj | Add-Member -Type NoteProperty -Name `"$($obj)" | |
} | |
$output += "`$obj" | |
$output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment