Get a list of Lync SBA’s via PowerShell

*****Updated 26 September 2016*****
Below is a much better way to get the list of SBA’s versus what I cobbled together below.

$registrars = get-csservice -registrar
$registrars | where {$_.Identity.split(":")[1] -ne $_.Webserver.split(":")[1]} | select Identity, UserServer

It looks at all registrars. If it does not have webservices then it is assumed to be an SBA/SBS.

*****Updated 24 June 2015*****

I can’t find an easy way to get a list of the SBA’s (and the occasional SBS) in our Lync environment. As such, I threw this script together. If someone has a better way to do this, by all means let me know as this is sort of a brute-force method.

$AllSites = get-cssite

Foreach($Site in $Allsites)
{
$i=0
If ($Site.ParentSite -ne $Null)
     {
     foreach($Service in $Site.Services)
          {
          if ($Service -notlike "PstnGateway*")
               {
               $i++
               }
          }
          If ($i -eq 2)
          {
               ForEach ($ServiceType in $Site.Services)
               {
                    if($ServiceType -like "Registrar:*")
                    {
                         $PoolName = $ServiceType.TrimStart("Registrar:")
                         write-host $Poolname
                    }
               }
           }
      }
}

Here is a quick breakdown of how this works. First it gathers a copy of the output from the get-cssite cmdlet. It then loops through each site. If the ParentSite attribute is null, then the given site cannot be for an SBA or an SBS so it throws that site away and loops to the next one. If it does have a ParentSite value it then checks to see if there are only 2 registered services. All SBA’s and SBS’s only have the following three services:
Registrar, MediationServer, and PSTNGateway

However, if there are multiple trunks defined, then there could be more than one PstnGateway service – 1 for each trunk. So the PstnGateway services get removed. If there are only 2 services left, then it’s assumed to be an SBA/SBS

If it has gotten this far then it is fairly certain that the given site hosts an SBA. The last step is to get the name of the SBA. This is done by grabbing the Registrar value from the Services attribute of the site and throwing away the “Registrar:” portion (which leaves the pool name which is the name of the SBS/SBA).

5 comments

Skip to comment form

  1. Thanks for this! I was scratching my head for a bit on this 🙂

    1. Also your code block has been html messed up e.g. "

  2. Thanks. That probably happened when migrating the site. I’ll get that cleaned up. Also, this isn’t 100% accurate. I need to revisit this someday – but it will find *most* SBA’s.

  3. Updated to better detect an SBA/SBS when there is more than 1 trunk defined.

    1. Nice one!

Leave a Reply

Your email address will not be published.