Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Prerequisites :
- # Update-Module MicrosoftTeams -RequiredVersion 5.5
- Disconnect-MgGraph
- Connect-MgGraph -Scopes "user.read.all"
- [array]$Guests = Get-MgUser -All -Filter "usertype eq 'Guest'"
- Write-Host ("{0} guest accounts found" -f $Guests.Count)
- $GuestList = [System.Collections.Generic.List[Object]]::new()
- ForEach ($Guest in $Guests) {
- $Domain = $Guest.Mail.Split("@")[1]
- $ReportLine = [PSCustomObject][Ordered]@{
- Guest = $Guest.Mail
- Domain = $Domain
- Name = $Guest.DisplayName }
- $GuestList.Add($ReportLine)
- }
- Write-Host ""
- Write-Host "Guest accounts found for the following domains"
- Write-Host "----------------------------------------------"
- $GuestList | Group-Object Domain | Sort-Object Name | Select-Object Name, Count
- $Domains = $GuestList | Sort-Object Domain -Unique | Select-Object -ExpandProperty Domain
- Write-Host "Connecting to Microsoft Teams to check current external access configuration"
- Disconnect-MicrosoftTeams
- Connect-MicrosoftTeams
- # Get current set of domains configured for Teams extrenal access
- $DomainConfiguration = Get-CsTenantFederationConfiguration | Select-Object -ExpandProperty AllowedDomains
- # Check the set of domains that aren't in the current configuration
- [array]$DomainsToAdd = $Domains | Where-Object {$_ -notin $DomainConfiguration.AllowedDomain.Domain}
- $Prompt = "Do you want to add the following domains to the list allowed for Teams external access? " + $DomainsToAdd -join ", "
- $Choice = Read-Host $Prompt
- #Type Y to add detected domains
- If (($Choice.ToUpper()) -eq "Y") {
- $AllList = new-object object[] $DomainsToAdd.Count
- $i = 0
- ForEach ($Domain in $DomainsToAdd) {
- $x = New-CsEdgeDomainPattern -Domain $Domain
- $AllList[$i] = $x
- $i++
- }
- $newAllowList = New-CsEdgeAllowList -AllowedDomain @($AllList)
- # replace the current domains list for the new list generated above
- Set-CsTenantFederationConfiguration -AllowedDomains $newAllowList
- }
- $DomainConfiguration = Get-CsTenantFederationConfiguration | Select-Object -ExpandProperty AllowedDomains
- Write-Host ("External access for Teams now includes {0} domains" -f $DomainConfiguration.AllowedDomain.Domain.count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement