start-HTMLOutput.ps1


function get-NodeString
{
    param(
        [Parameter(Mandatory = $true)]
        $node,
        [Parameter(Mandatory = $true)]
        $outputType
    )

    $functionReturnString = ""

    if ($outputType -eq $functionExchangeOnlineType)
    {
        out-logfile -string "Calculating string for Exchange Online"

        if ($node.object.groupType -ne $null)
        {
            if ($node.object.IsMembershipDynamic -eq $true)
            {
                if ($reverseHierarchy -eq $FALSE)
                {
                    $functionReturnString = $node.object.displayName +" (ExchangeObjectID: "+$node.object.ExchangeObjectID+") ("+$node.object.recipientType+"/"+$node.object.recipientTypeDetails+"/"+$node.object.GroupType+") (DynamicMembership)"
                }
                else 
                {
                    $functionReturnString = $node.object.displayName +" (ExchangeObjectID: "+$node.object.ExchangeObjectID+") ("+$node.object.recipientType+"/"+$node.object.recipientTypeDetails+"/"+$node.object.GroupType+") (DynamicMembership) [Parent Group]"
                }
            }
            else 
            {
                if ($reverseHierarchy -eq $FALSE)
                {
                    $functionReturnString = $node.object.displayName +" (ExchangeObjectID: "+$node.object.ExchangeObjectID+") ("+$node.object.recipientType+"/"+$node.object.recipientTypeDetails+"/"+$node.object.GroupType+")"
                }
                else 
                {
                    $functionReturnString = $node.object.displayName +" (ExchangeObjectID: "+$node.object.ExchangeObjectID+") ("+$node.object.recipientType+"/"+$node.object.recipientTypeDetails+"/"+$node.object.GroupType+") [Parent Group]"
                }
            }
        }
        else 
        {
            $functionReturnString = $node.object.displayName +" (ExchangeObjectID: "+$node.object.ExchangeObjectID+") ("+$node.object.recipientType+"/"+$node.object.recipientTypeDetails+")"
        }
    }
    elseif ($outputType -eq $functionMSGraphType)
    {
        out-logfile -string "Calculating string for Microsoft Graph"

        if ($node.object.groupTypes -ne $NULL)
        {
            out-logfile -string "Group type is not NULL - calculate string for group"

            if ($reverseHierarchy -eq $FALSE)
            {
                out-logfile -string "Reverse hierarchy is set to false."

                $functionReturnString = $node.object.displayName +" (ObjectID: "+$node.object.id+") ("+$node.object.getType().name+") ("+$node.object.groupTypes+")"
            }
            else 
            {
                out-logfile -string "Reverse hierarchy is set to true."

                $functionReturnString = $node.object.displayName +" (ObjectID: "+$node.object.id+") ("+$node.object.getType().name+") ("+$node.object.groupTypes+") [Parent Group]"
            }
        }
        else 
        {
            if ($reverseHierarchy -eq $FALSE)
            {
                $functionReturnString = $node.object.displayName +" (ObjectID: "+$node.object.id+") ("+$node.object.getType().name+")"
            }
            else 
            {
                $functionReturnString = $node.object.displayName +" (ObjectID: "+$node.object.id+") ("+$node.object.getType().name+") [Parent Group]"
            }
        }
    }
    elseif ($outputType -eq $functionLDAPType)
    {
        out-logfile -string "Calculating string for LDAP"

        if ($reverseHierarchy -eq $FALSE)
        {
            $functionReturnString = $node.object.DisplayName +" (ObjectGUID:"+$node.object.objectGUID+") ("+$node.object.objectClass+")"
        }
        else 
        {
            if ($node.object.objectClass -eq "Group")
            {
                $functionReturnString = $node.object.DisplayName +" (ObjectGUID:"+$node.object.objectGUID+") ("+$node.object.objectClass+") [Parent Group]"
            }
            else 
            {
                $functionReturnString = $node.object.DisplayName +" (ObjectGUID:"+$node.object.objectGUID+") ("+$node.object.objectClass+")"
            }
        }
    }

    out-logfile -string $functionReturnString
    return $functionReturnString
}
function New-HTMLTreeChildNodes 
{
    param(
        [Parameter(Mandatory = $true)]
        $node,
        [Parameter(Mandatory = $true)]
        $outputType
    )

    $functionGraphUser = "MicrosoftGraphUser"
    $functionGraphGroup = "MicrosoftGraphGroup"
    $functionGraphContact = "MicrosoftGraphOrgContact"

    $functionExchangeGroup = "Group"
    $functionExchangeMailUniversalSecurityGroup = "MailUniversalSecurityGroup"
    $functionExchangeMailUniversalDistributionGroup = "MailUniversalDistributionGroup"
    $functionExchangeUserMailbox = "UserMailbox"
    $functionExchangeMailUser = "Mailuser"
    $functionExchangeGuestMailUser = "GuestMailUser"
    $functionExchangeMailContact = "MailContact"
    $functionExchangeGroupMailbox = "GroupMailbox"
    $functionExchangeDynamicGroup = "DynamicDistributionGroup"

    $functionLDAPGroup = "Group"
    $functionLDAPUser = "User"
    $functionLDAPContact = "Contact"
    $functionLDAPDynamicGroup = "msExchDynamicDistributionList"

    if ($outputType -eq $functionMSGraphType)
    {

        $sorted = New-Object System.Collections.Generic.List[pscustomobject]
        $node.Children | % { $sorted.Add($_) }
        
        $sorted = [System.Linq.Enumerable]::OrderBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.additionalproperties.'@odata.context' })
        $sorted = [System.Linq.Enumerable]::ThenBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.DisplayName })

        foreach ($child in $sorted)
        {
            $string = get-nodeString -node $child -outputType $functionMSGraphType
            out-logfile -string ("Prcessing HTML: "+$string)

            if ($child.object.getType().name -eq $functionGraphUser)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionMSGraphType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.getType().name -eq $functionGraphGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionMSGraphType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.getType().name -eq $functionGraphContact)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionMSGraphType} -icon $functionContactPNGHTML
            }
        }
    }
    elseif ($outputType -eq $functionExchangeOnlineType)
    {
        $sorted = New-Object System.Collections.Generic.List[pscustomobject]
        $node.Children | % { $sorted.Add($_) }
     
        $sorted = [System.Linq.Enumerable]::OrderBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.RecipientTypeDetails })
        $sorted = [System.Linq.Enumerable]::ThenBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.DisplayName })

        foreach ($child in $sorted)
        {
            $string = get-nodeString -node $child -outputType $functionExchangeOnlineType
            out-logfile -string ("Prcessing HTML: "+$string)

            if ($child.object.recipientType -eq $functionExchangeGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeMailUniversalSecurityGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeDynamicGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeMailUniversalDistributionGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeGroupMailbox)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeGuestMailUser)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeMailUser)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeUserMailbox)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeUser)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.recipientType -eq $functionExchangeMailContact)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionExchangeOnlineType} -icon $functionContactPNGHTML
            }
        }
    }
    elseif ($outputType -eq $functionLDAPType)
    {
        $sorted = New-Object System.Collections.Generic.List[pscustomobject]
        $node.Children | % { $sorted.Add($_) }
     
        $sorted = [System.Linq.Enumerable]::OrderBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.objectClass })
        $sorted = [System.Linq.Enumerable]::ThenBy($sorted, [Func[pscustomobject,string]]{ param($x) $x.Object.Name })

        foreach ($child in $sorted)
        {
            $string = get-nodeString -node $child -outputType $functionLDAPType
            out-logfile -string ("Prcessing HTML: "+$string)

            if ($child.object.objectClass -eq  $functionLDAPGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionLDAPType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.objectClass -eq  $functionLDAPDynamicGroup)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionLDAPType} -icon $functionGroupPNGHTML
            }
            elseif ($child.object.objectClass -eq  $functionLDAPUser)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionLDAPType} -icon $functionUserPNGHTML
            }
            elseif ($child.object.objectClass -eq  $functionLDAPContact)
            {
                New-HTMLTreeNode -Title $string -children {New-HTMLTreeChildNodes -node $child -outputType $functionLDAPType} -icon $functionContactPNGHTML
            }
        }
    }
}


function start-HTMLOutput
{
    param(
        [Parameter(Mandatory = $true)]
        $node,
        [Parameter(Mandatory = $true)]
        $outputType,
        [Parameter(Mandatory = $true)]
        $groupObjectID,
        [Parameter(Mandatory =$FALSE)]
        [boolean]$reverseHierarchy=$FALSE,
        [Parameter(Mandatory =$FALSE)]
        [boolean]$isHealthCheck=$FALSE
    )

    $functionMSGraphType = "MSGraph"
    $functionExchangeOnlineType = "ExchangeOnline"
    $functionLDAPType = "LDAP"

    $functionContactPNGHTML = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAMCAMAAABcOc2zAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UT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0aW1lc3RhbXAAMjAyNC0wMi0yOVQyMDo1NDoxMyswMDowMG8WJu8AAAAASUVORK5CYII="


    $functionHTMLSuffix = "html"
    $functionHTMLLDAPSuffix  = "-LDAP.html"
    $functionHTMLLDAPReverseSuffix  = "-LDAPReverse.html"
    $functionHTMLGraphSuffix  = "-Graph.html"
    $functionHTMLGraphReverseSuffix  = "-GraphReverse.html"
    $functionExchangeSuffix  = "-Exchange.html"
    $functionExchangeReverseSuffix  = "-ExchangeReverse.html"

    if (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $FALSE) -and ($outputType -eq $functionLDAPType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionHTMLLDAPSuffix)   
    }
    elseif (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $true) -and ($outputType -eq $functionLDAPType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionHTMLLDAPReverseSuffix)   
    }
    elseif (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $FALSE) -and ($outputType -eq $functionMSGraphType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionHTMLGraphSuffix)   
    }
    elseif (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $true) -and ($outputType -eq $functionMSGraphType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionHTMLGraphReverseSuffix)   
    }
    elseif (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $FALSE) -and ($outputType -eq $functionExchangeOnlineType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionExchangeSuffix)   
    }
    elseif (($isHealthCheck -eq $TRUE) -and ($reverseHierarchy -eq $true) -and ($outputType -eq $functionExchangeOnlineType))
    {
        $global:functionHTMLFile = $global:LogFile.replace(".log",$functionExchangeReverseSuffix)   
    }
    else 
    {
        $global:functionHTMLFile = $global:LogFile.replace("log",$functionHTMLSuffix)    
    }
    

    if (($reverseHierarchy -eq $true) -and ($outputType -eq $functionExchangeOnlineType))
    {
        $headerString = ("***Exchange Based Group Hierarchy in REVERSE for: "+$groupObjectID+"***")
    }
    elseif (($reverseHierarchy -eq $true) -and ($outputType -eq $functionMSGraphType))
    {
        $headerString = ("***Graph Based Group Hierarchy in REVERSE for: "+$groupObjectID+"***")
    }
    elseif (($reverseHierarchy -eq $true) -and ($outputType -eq $functionLDAPType))
    {
        $headerString = ("***LDAP Based Group Hierarchy in REVERSE for: "+$groupObjectID+"***")
    }
    elseif ($outputType -eq $functionExchangeOnlineType)
    {
        $headerString = ("***Exchange Based Group Hierarchy for: "+$groupObjectID+"***")
    }
    elseif ($outputType -eq $functionMSGraphType)
    {
        $headerString = ("***Graph Based Group Hierarchy for: "+$groupObjectID+"***")
    }
    elseif ($outputType -eq $functionLDAPType)
    {
        $headerString = ("***LDAP Based Group Hierarchy for: "+$groupObjectID+"***")
    }

    out-logfile -string $global:functionHTMLFile
    out-logfile -string $outputType

    if ($isHealthCheck -eq $FALSE)
    {
        if ($outputType -eq $functionExchangeOnlineType)
        {
            out-logfile -string "Entering Exchange Online Type"

            $string = get-nodeString -node $node -outputType $functionExchangeOnlineType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                new-htmlMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    }-HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable ($global:exchangeObjects | select-object DisplayName,Alias,ExternalDirectoryObjectId,ExchangeObjectId,Identity,ID,Name,PrimarySmtpAddress,EmailAddresses,LegacyExchangeDN,externalEmailAddress,RecipientType,RecipientTypeDetails,GroupType,IsDirSynced | sort-object exchangeObjectID -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                                new-ChartDonut -Name 'MailSecurityGroups' -value $global:mailUniversalSecurityGroupCounter.count
                                new-chartDonut -name 'MailDistributionGroups' -value $global:mailUniversalDistributionGroupCounter.count
                                new-chartDonut -name 'UnifiedGroups' -value $global:groupMailboxCounter.count
                                new-chartDonut -name 'UnifiedGroups-Dynamic' -value $global:groupMailboxDyanmicCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'MailContacts' -Value $global:mailContactCounter.count
                                New-ChartDonut -Name 'GuestMailUsers' -Value $global:guestMailUserCounter.count
                                New-ChartDonut -Name 'MailUsers' -Value $global:mailUserCounter.count
                                New-ChartDonut -Name 'UserMailbox' -Value $global:userMailboxCounter.count
                                New-ChartDonut -Name 'RoomMailbox' -Value $global:roomMailboxCounter.count
                                New-ChartDonut -Name 'EqipmentMailbox' -Value $global:equipmentMailboxCounter.count
                                New-ChartDonut -Name 'SharedMailbox' -Value $global:sharedMailboxCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                                new-ChartDonut -Name 'MailSecurityGroups' -value $global:mailUniversalSecurityGroupCounter.count
                                new-chartDonut -name 'MailDistributionGroups' -value $global:mailUniversalDistributionGroupCounter.count
                                new-chartDonut -name 'UnifiedGroups' -value $global:groupMailboxCounter.count
                                new-chartDonut -name 'UnifiedGroups-Dynamic' -value $global:groupMailboxDyanmicCounter.count
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'MailContacts' -Value $global:mailContactCounter.count
                                New-ChartDonut -Name 'GuestMailUsers' -Value $global:guestMailUserCounter.count
                                New-ChartDonut -Name 'MailUsers' -Value $global:mailUserCounter.count
                                New-ChartDonut -Name 'UserMailbox' -Value $global:userMailboxCounter.count
                                New-ChartDonut -Name 'RoomMailbox' -Value $global:roomMailboxCounter.count
                                New-ChartDonut -Name 'EqipmentMailbox' -Value $global:equipmentMailboxCounter.count
                                New-ChartDonut -Name 'SharedMailbox' -Value $global:sharedMailboxCounter.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                } 
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            } -Online -ShowHTML
        }
        elseif ($outputType -eq $functionMSGraphType)
        {
            out-logfile -string "Entering MS Graph Type"

            $string = get-nodeString -node $node -outputType $functionMSGraphType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                New-HTMLMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLHeading -HeadingText ('Group Expansion for: '+$groupObjectID) -Heading h1
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionMSGraphType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    }-HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable ($global:msGraphObjects | select-object DisplayName,Id,Mail,MailEnabled,MailNickname,ProxyAddresses,GroupTypes,SecurityEnabled,MembershipRule | sort-object ID -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:msGraphGroupCount.count
                                New-ChartDonut -name 'DynamnicGroups' -value $global:msGraphGroupDynamicCount.Count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:msGraphUserCount.count
                                new-ChartDonut -Name 'Contacts' -value $global:msGraphContactCount.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:msGraphGroupCount.count
                                New-ChartDonut -name 'DynamnicGroups' -value $global:msGraphGroupDynamicCount.Count
                                New-ChartDonut -Name 'Users' -Value $global:msGraphUserCount.count
                                new-ChartDonut -Name 'Contacts' -value $global:msGraphContactCount.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                }
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            } -Online -ShowHTML
        }
        elseif ($outputType -eq $functionLDAPType)
        {
            out-logfile -string "Entering LDAP Type"

            $string = get-nodeString -node $node -outputType $functionLDAPType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                new-htmlMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionLDAPType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable (($global:ldapObjects | select-object DistinguishedName,CanonicalName,objectGUID,Name,DisplayName,groupType,mail,mailnickanme,proxyAddresses,targetAddress,legacyExchangeDN,'mS-DS-ConsistencyGuid','msDS-ExternalDirectoryObjectId',msExchRecipientDisplayType,msExchRecipientTypeDetails,msExchRemoteRecipientType,msExchMailboxGuid,msExchArchiveGUID) | sort-object distinguishedName -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'Contacts' -Value $global:contactCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'Contacts' -Value $global:contactCounter.count
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                    new-htmlSection -HeaderText ("Parents (Reverse) or Chilren (Normal) Simplied Group List"){
                        new-htmlTable -DataTable $global:groupTracking -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px
                }
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            } -Online -ShowHTML 
        }
    }
    else 
    {
        if ($outputType -eq $functionExchangeOnlineType)
        {
            out-logfile -string "Entering Exchange Online Type"

            $string = get-nodeString -node $node -outputType $functionExchangeOnlineType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                new-htmlMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionExchangeOnlineType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    }-HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable ($global:exchangeObjects | select-object DisplayName,Alias,ExternalDirectoryObjectId,ExchangeObjectId,Identity,ID,Name,PrimarySmtpAddress,EmailAddresses,LegacyExchangeDN,externalEmailAddress,RecipientType,RecipientTypeDetails,GroupType,IsDirSynced | sort-object exchangeObjectID -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                                new-ChartDonut -Name 'MailSecurityGroups' -value $global:mailUniversalSecurityGroupCounter.count
                                new-chartDonut -name 'MailDistributionGroups' -value $global:mailUniversalDistributionGroupCounter.count
                                new-chartDonut -name 'UnifiedGroups' -value $global:groupMailboxCounter.count
                                new-chartDonut -name 'UnifiedGroups-Dynamic' -value $global:groupMailboxDyanmicCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'MailContacts' -Value $global:mailContactCounter.count
                                New-ChartDonut -Name 'GuestMailUsers' -Value $global:guestMailUserCounter.count
                                New-ChartDonut -Name 'MailUsers' -Value $global:mailUserCounter.count
                                New-ChartDonut -Name 'UserMailbox' -Value $global:userMailboxCounter.count
                                New-ChartDonut -Name 'RoomMailbox' -Value $global:roomMailboxCounter.count
                                New-ChartDonut -Name 'EqipmentMailbox' -Value $global:equipmentMailboxCounter.count
                                New-ChartDonut -Name 'SharedMailbox' -Value $global:sharedMailboxCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                                new-ChartDonut -Name 'MailSecurityGroups' -value $global:mailUniversalSecurityGroupCounter.count
                                new-chartDonut -name 'MailDistributionGroups' -value $global:mailUniversalDistributionGroupCounter.count
                                new-chartDonut -name 'UnifiedGroups' -value $global:groupMailboxCounter.count
                                new-chartDonut -name 'UnifiedGroups-Dynamic' -value $global:groupMailboxDyanmicCounter.count
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'MailContacts' -Value $global:mailContactCounter.count
                                New-ChartDonut -Name 'GuestMailUsers' -Value $global:guestMailUserCounter.count
                                New-ChartDonut -Name 'MailUsers' -Value $global:mailUserCounter.count
                                New-ChartDonut -Name 'UserMailbox' -Value $global:userMailboxCounter.count
                                New-ChartDonut -Name 'RoomMailbox' -Value $global:roomMailboxCounter.count
                                New-ChartDonut -Name 'EqipmentMailbox' -Value $global:equipmentMailboxCounter.count
                                New-ChartDonut -Name 'SharedMailbox' -Value $global:sharedMailboxCounter.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                } 
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            }-Online
        }
        elseif ($outputType -eq $functionMSGraphType)
        {
            out-logfile -string "Entering MS Graph Type"

            $string = get-nodeString -node $node -outputType $functionMSGraphType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                New-HTMLMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLHeading -HeadingText ('Group Expansion for: '+$groupObjectID) -Heading h1
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionMSGraphType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    }-HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable ($global:msGraphObjects | select-object DisplayName,Id,Mail,MailEnabled,MailNickname,ProxyAddresses,GroupTypes,SecurityEnabled,MembershipRule | sort-object ID -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:msGraphGroupCount.count
                                New-ChartDonut -name 'DynamnicGroups' -value $global:msGraphGroupDynamicCount.Count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:msGraphUserCount.count
                                new-ChartDonut -Name 'Contacts' -value $global:msGraphContactCount.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:msGraphGroupCount.count
                                New-ChartDonut -name 'DynamnicGroups' -value $global:msGraphGroupDynamicCount.Count
                                New-ChartDonut -Name 'Users' -Value $global:msGraphUserCount.count
                                new-ChartDonut -Name 'Contacts' -value $global:msGraphContactCount.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                }
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            }-Online
        }
        elseif ($outputType -eq $functionLDAPType)
        {
            out-logfile -string "Entering LDAP Type"

            $string = get-nodeString -node $node -outputType $functionLDAPType
            out-logfile -string ("Prcessing HTML: "+$string)

            New-HTML -TitleText $groupObjectID -FilePath $global:functionHTMLFile {
                New-HTMLHeader{
                    New-HTMLText -Text $headerString -FontSize 24 -Color White -BackGroundColor Black -Alignment center
                }
                new-htmlMain{
                    New-HTMLTableOption -DataStore JavaScript
                    new-htmlSection -HeaderText ("Group membership hierarchy for group object id: "+$groupObjectID){
                        New-HTMLTree -Checkbox none {
                            New-HTMLTreeChildCounter -Deep -HideZero -HideExpanded
                            New-HTMLTreeNode -title $string -children {New-HTMLTreeChildNodes -node $node -outputType $functionLDAPType} -icon $functionGroupPNGHTML
                        } -EnableChildCounter -AutoScroll -MinimumExpandLevel 1 -EnableQuickSearch
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership table for group object id: "+$groupObjectID){
                        new-htmlTable -DataTable (($global:ldapObjects | select-object DistinguishedName,CanonicalName,objectGUID,Name,DisplayName,groupType,mail,mailnickanme,proxyAddresses,targetAddress,legacyExchangeDN,'mS-DS-ConsistencyGuid','msDS-ExternalDirectoryObjectId',msExchRecipientDisplayType,msExchRecipientTypeDetails,msExchRemoteRecipientType,msExchMailboxGuid,msExchArchiveGUID) | sort-object distinguishedName -Unique) -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Group membership breakdown for group object id: "+$groupObjectID){
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'Contacts' -Value $global:contactCounter.count
                            }
                        }
                        New-HTMLPanel {
                            New-HTMLChart -Gradient {
                                New-ChartDonut -Name 'Users' -Value $global:userCounter.count
                                New-ChartDonut -Name 'Contacts' -Value $global:contactCounter.count
                                New-ChartDonut -Name 'Groups' -Value $global:groupCounter.count
                                New-ChartDonut -Name 'DynamicGroups' -Value $global:dynamicGroupCounter.count
                            }
                        }
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                    new-htmlSection -HeaderText ("Parents (Reverse) or Chilren (Normal) Simplied Group List"){
                        new-htmlTable -DataTable $global:groupTracking -Filtering {
                        } -AutoSize
                    } -HeaderTextAlignment "Left" -HeaderTextSize "16" -HeaderTextColor "White" -HeaderBackGroundColor "Black"  -CanCollapse -BorderRadius 10px -Collapsed
                }
                New-HTMLFooter {
                    New-HTMLText -Text "Date of this report $(Get-Date)" -FontSize 16 -Color White -BackGroundColor Black -Alignment center
                }
            }-Online
        }
    }
}