Functions/Convert-AzureADUserToMSPCompleteUser.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 46 |
<#
.SYNOPSIS This function converts an Azure AD user to a MSPComplete user. .DESCRIPTION This function converts an Azure AD user to a MSPComplete user. The conversion is accomplished by mapping the Azure AD user's properties and extended properties to their corresponding MSPComplete properties. #> function Convert-AzureADUserToMSPCompleteUser { [CmdletBinding(PositionalBinding=$true)] [OutputType([PSCustomObject])] param ( # The Azure AD User. [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [ValidateNotNull()] [PSCustomObject]$user ) # Create the MSPComplete user object $mspCompleteUser = [PSCustomObject]@{} # Retrieve the mapping from MSPComplete user to Azure AD user properties $propertyMap = Get-MSPCompleteUserToAzureADUserPropertyMap # Add all properties to the MSPComplete user foreach ($property in $propertyMap.GetEnumerator()) { if (![String]::IsNullOrWhiteSpace($user.($property.Value))) { $mspCompleteUser | Add-Member -NotePropertyName $property.Key -NotePropertyValue $user.($property.Value) } } # Retrieve the map from MSPComplete user extended properties to Azure AD user properties $extendedPropertyMap = Get-MSPCompleteUserToAzureADUserExtendedPropertyMap # Convert the extended properties to the MSPComplete user $mspCompleteUser | Add-Member -NotePropertyName "ExtendedProperties" -NotePropertyValue @{} foreach ($property in $extendedPropertyMap.GetEnumerator()) { if (![String]::IsNullOrWhiteSpace($user.($property.Value))) { $mspCompleteUser.ExtendedProperties.Add($property.Key, $user.($property.Value)) } } # Return the converted user return $mspCompleteUser } |