Public/Invoke-AddGroupMember.ps1

function Invoke-AddGroupMember {
    <#
    .SYNOPSIS
        Adds user to a certain group
    .PARAMETER UserName
        Target user
    .PARAMETER GroupType
        Options are basic, standard, and mfa
    .EXAMPLE
        !add dk.test.hz basic|standard|mfa
    #>

    [PoshBot.BotCommand(
        CommandName = 'addgroup',
        Aliases = ('addlicense', 'member', 'license')
    )]
    [cmdletbinding()]
    param(
        [parameter(Mandatory)]
        [string]$username,
        [parameter(Mandatory)]
        [string]$grouptype
    )
    Import-Module ActiveDirectory
    $searchname = '*' + $username + '*'

    try {
        $GCADUser = Get-ADUser -Filter { (((SamAccountName -like $searchname) -or (Name -like $searchname)) -and ((Enabled -eq $true) -and (mail -like "*"))) } -Server sundc1:3268
        New-PoshBotCardResponse -Text ($GCADUser | Out-String) -Title "Found user in AD"
    }
    catch {
        Write-Output "$($_.Exception.Message)"
        Write-Output "$($_.error.message)"
    }

    if ($null -ne $GCADUser) {
        try {
            switch ($grouptype) {
                "basic" {
                    $group = Get-ADGroup -Identity "sunssc.M365-business-basic.usg"
                    Add-ADGroupMember -identity "sunssc.M365-business-basic.usg" -Members $GCADUser
                }
                "standard" {
                    $group = Get-ADGroup -Identity "sunssc.M365-business-standard.usg"
                    Add-ADGroupMember -identity "sunssc.M365-business-standard.usg" -Members $GCADUser
                }
                "mfa" {
                    $group = Get-ADGroup -Identity "sunssc.Azure-MFA-users.usg"
                    Add-ADGroupMember -identity "sunssc.Azure-MFA-users.usg" -Members $GCADUser
                }
            }
            New-PoshBotCardResponse -Text ("$GCADUser.DistinguishedName has been added to $group.distinguishedname!")
            Start-Sleep -seconds 60
            $result = Invoke-Command -ComputerName "sun-aad.sunssc.local" -ScriptBlock {
                Start-ADSyncSyncCycle -PolicyType Delta
            }
            New-PoshBotCardResponse -Type Normal -Text ($result | format-list -property * | out-string) -Title "Sync Azure AD"
        }
        catch {
            Write-Output "$($_.Exception.Message)"
            Write-Output "$($_.error.message)"
        }
    }
}