Email notification with external members in Teams team.


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:

<span style="font-family:Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', 'Courier 10 Pitch', Courier, monospace;">#Remeber to log on to Exchange Online and Teams in PowerShell</span>
$EmailCredential = Get-Credential
$Groups = (Get-Team).GroupID | Get-UnifiedGroup
$Info = @()

foreach($group in $Groups){
$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){
Name = $User.displayname
Email = $User.primarysmtpaddress
"No external members in $GroupAlias"
Else {
$info2 = $info | Out-String
Send-MailMessage -From [email protected] -To "$owneremail" -Subject "Can any of these External Members on your Team $GroupAlias be disabled?" -Body $info2 -credential $EmailCredential -SmtpServer "" -UseSsl
$info = @()
Email sent to these owners: $ownersemail"


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s