Hey again!
Have you been searching and looking around to find a way to automate or use PowerShell for adding federation partners to Skype for Business Online?
Then here’s a great example for you, feel free to use the script, edit and tweak it. If you do tweak and edit/improving it. Please go ahead and share it with the community and also link to my blog post.
In my case I’m using PowerShell version 5 together with Skype for Business module, which is a requirement for connecting to the cloud service(s).
The script in itself is pretty much straight forward, type in one or more domains and they get added into the alloweddomains list.
This can be handy if you’re not using open federation and have to add a couple of new domains every now and then..
<# .SYNOPSIS Filename: Add-CsFedDomain.psm1 Jonas Andersson Jonas.Andersson@testlabs.se THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. Version 1.0, September 25th, 2016 .DESCRIPTION Used for adding new domain(s) for Skype for Business Online .PREREQUISITES Connect to Skype for Business Online using the PowerShell module Revision History -------------------------------------------------------------------------------- 1.0 Initial release .EXAMPLE Add-CsFederationDomain -domainName domain1.com Add-CsFederationDomain -domainName domain1.com,domain2.com,domain3.com #> function Add-CsFederationDomain ( [Parameter(Mandatory = $true)][array]$domainName ) { if ((Get-MsolDomain -ErrorAction 0) -eq $null) { Write-Host "Not connected to O365, use ConnectToO365-P*" -ForegroundColor Red break } $tenant = Get-CsTenant $domainName = $domainName.split(",") $domainName = $domainName.split(";") $domainName = $domainName.split(",") $domainName = $domainName.Replace(" ","") if ($domainName.Count -lt 2) { [string]$domainName = $domainName[0].ToString() Write-Host "#########################################################################################" -ForegroundColor White Write-Host "Domain: $domainName" -ForegroundColor DarkGreen $x = Get-CsTenantFederationConfiguration –Tenant $tenant.TenantId $domain = $x.AllowedDomains.AllowedDomain | ?{$_.Domain -eq $domainName} if ($domain -eq $null) { $d1 = New-CsEdgeDomainPattern -Domain $domainName $x.AllowedDomains.AllowedDomain.Add($d1) Set-CsTenantFederationConfiguration -Tenant $tenant.tenantID -AllowedDomains $x.AllowedDomains Write-Host "Domain $domainName was added successfully" -ForegroundColor Green } else { Write-Host "ERROR: $domainName already in allowed list" -ForegroundColor Red } } if ($domainName.Count -gt 1) { foreach ($newdomain in $domainName) { Write-Host "#########################################################################################" -ForegroundColor White Write-Host "Domain: $newdomain" -ForegroundColor DarkGreen $x = Get-CsTenantFederationConfiguration –Tenant $tenant.TenantId $domain = $x.AllowedDomains.AllowedDomain | Where-Object {$_.Domain -eq $newdomain} if ($domain -eq $null) { $d1 = New-CsEdgeDomainPattern -Domain $newdomain $x.AllowedDomains.AllowedDomain.Add($d1) Set-CsTenantFederationConfiguration -Tenant $tenant.tenantID -AllowedDomains $x.AllowedDomains Write-Host "Domain $newdomain was added successfully" -ForegroundColor Green } else { Write-Host "ERROR: $newdomain already in allowed list" -ForegroundColor Red } } } }
Inspiration from this great blog post:
https://gotspeechguy.com/2012/06/21/setting-up-a-tenants-allowed-domains-for-federation/