if (($RoleIsDatacenter -ne $true) -and ($RoleIsDatacenterDedicated -ne $true)) { if (test-ExchangeServersWriteAccess -DomainController ...

if (($RoleIsDatacenter -ne $true) -and ($RoleIsDatacenterDedicated -ne $true))          {            if (test-ExchangeServersWriteAccess -DomainController $RoleDomainController -ErrorAction SilentlyContinue)            {              # upgrade the discovery mailboxes to R5 version, this will fix the RecipientDisplayType property of the discovery mailbox which was wrong in R4.              get-mailbox -RecipientTypeDetails DiscoveryMailbox -DomainController $RoleDomainController | where {$_.IsValid -eq $false} | set-mailbox -DomainController $RoleDomainController              $name = [Microsoft.Exchange.Management.RecipientTasks.EnableMailbox]::DiscoveryMailboxUniqueName;              $dispname = [Microsoft.Exchange.Management.RecipientTasks.EnableMailbox]::DiscoveryMailboxDisplayName;              $mbxs = @( get-mailbox -Filter {name -eq $name} -IgnoreDefaultScope -resultSize 1 );              if ( $mbxs.length -eq 0)               {                $dbs = @(get-MailboxDatabase -Server:$RoleFqdnOrName -DomainController $RoleDomainController);                if($dbs.Length -ne 0)                 {                  $mbxUser = @(get-user -Filter {name -eq $name} -IgnoreDefaultScope -ResultSize 1);                  if ($mbxUser.Length -ne 0)                   {                    enable-mailbox -Discovery -identity $mbxUser[0] -DisplayName $dispname -database $dbs[0].Identity;                  }                }              }            }            else            {              write-exchangesetuplog -info "Skipping creating Discovery Search Mailbox because of insufficient permission."            }            }