Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/
# 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