Email notification with external members in Teams team.

microsoft-teams.png

Been over a month since my last blogpost. I have been completely out of ides on what to blog about or what to script. Twitter to the rescue. Did not take long time after asking that i got some ideas on what i could script. So this is what i decided on doing:

My script does exactly what Max requested, and here it is:

#Remeber to log on to Exchange Online.
$EmailCredential = Get-Credential
$Groups = Get-UnifiedGroup
$Info = @()

foreach($group in $Groups){
$TeamsEnabledCheck = Get-MailboxFolderStatistics -Identity $Group.Alias -IncludeOldestAndNewestItems -FolderScope ConversationHistory | Select-Object FolderType
If ($TeamsEnabledCheck.FolderType -like 'TeamChat') {

$Owners = Get-UnifiedGroupLinks $group.Alias -LinkType owners
$Ownersemail = $Owners.primarysmtpaddress -join ', '
$GroupAlias = $Group.Alias
$Users = Get-UnifiedGroupLinks $Group.Alias  -LinkType members | Where-Object {$_.RecipientTypeDetails -eq "GuestMailUser"}
    foreach($User in $Users){
        $Object=[PSCustomObject]@{
        Name = $User.displayname
        Email = $User.primarysmtpaddress
        }
        $script:info+=$Object
    }
    If(!$info){
        "No external members in $GroupAlias"
    }
    Else {
    $info2 = $info | Out-String
    Send-MailMessage -From admin@contoso.com -To "$owneremail" -Subject "Can any of these External Members on your Team $GroupAlias be disabled?" -Body $info2 -credential $EmailCredential -SmtpServer "smtp.office365.com" -UseSsl
    $info = @()
    "$GroupAlias
    Email sent to these owners: $ownersemail"
    }

    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s