Functions/Convert-AzureADUserToMSPCompleteUser.ps1
<#
.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 } |