Powershell Script For a Lync Client to probe DNS and test that it can contact the access edge server


Here is a quick script you can give to lync clients to help them determine the first basics steps in troubleshooting a signon failure...

This script will prompt for the users signin address, it will take it discover the sip domain and the srv records

then it will try and ping and connect to the servers

this will give the user an idea of they have the basic connectivity needed for lync to sign on.....

 

Hope it helps

 

As always feedback always welcome!

 

#This script performs a very simple test from the client. it will perform a DNS lookup for the SRV record
#It will then try and ping and open a connection to the server, it will tell you if it was successful or not.
#Written by John McCabe. PFE, Microsoft
#Comments welcome to johm@microsoft.com or on Twitter @mccabej

#Initialize Variables

$sipaddress = $null
$sipdomain = $null
$nameserver = $null
$sipsrv = $null
$sipsrvfed = $null
$dnscheck1 = $null
$dnscheck2 = $null
$dnscmd = $null
$dnsresults = $null
$dnscmd1 = $null
$dnsresults1 = $null
$sipAhost = $null
$sipaport = $null
$sipAhost1 = $null
$sipaport1 = $null
$siphost = $null
$sipport = $null
$siphost1 = $null
$sipport1 = $null
$dnscheckhost = $null
$dnscheckport = $null
$dnscheckhost1 = $null
$dnscheckport1 = $null

#define functions
Function pinghost
{
 
 param ([string]$testhost)
 $pingcmd = test-connection -ComputerName $testhost -Quiet
  
 if ($pingcmd -match "False")
 {
  Write-Host "Cannot ping : " $testhost -ForegroundColor Red -BackgroundColor Black
  Write-Host "Dont worry sometimes companies block ICMP" -ForegroundColor Red -BackgroundColor Black
 }
 else
 {
  Write-Host "Successfully pinged : " $testhost -ForegroundColor Blue -BackgroundColor White
 }
 
 

function testtcp
{
  
 
  Param([string]$ComputerName,[int]$port)

  $ErrorActionPreference = “SilentlyContinue”

  $socket = new-object Net.Sockets.TcpClient

  $socket.Connect($ComputerName, $port)

  if ($socket.Connected)
  {

    write-host "We have successfully connected to the server" -ForegroundColor Yellow -BackgroundColor Black

    $socket.Close()

  }

  else
  {

   write-host "The port seems to be closed or you cannot connect to it" -ForegroundColor Red -BackgroundColor Black

  }

  $socket = $null

}

#This main Script will test your connection from a perspective of the client

#Collect the users sign in address.... we dont query whoami /upn as the upn can be different then the actual sip address

$sipaddress = Read-host "Please Enter Your Sign In Address and Press Enter"
$sipdomain = $sipaddress.split("@")
Write-host "Your SIP Domain is: " $sipdomain[1]
Write-Host

$nameserver = "8.8.8.8"
$sipsrv = "_sip._tls."
$sipsrvfed = "_sipfederationtls._tcp."
$dnscheck1 = $sipsrv + $sipdomain[1]
$dnscheck2 = $sipsrvfed + $sipdomain[1]

Write-Host "Resolving Host Record for SIP Autodiscover...."
Write-Host

$dnscmd = "nslookup -type=srv " + $dnscheck1 + " " + $nameserver
$dnsresults = Invoke-Expression $dnscmd
$dnscmd1 = "nslookup -type=srv " + $dnscheck2 + " " + $nameserver
$dnsresults1 = Invoke-Expression $dnscmd1
$sipAhost = $dnsresults.SyncRoot[7]
$sipaport = $dnsresults.syncroot[6]
$sipAhost1 = $dnsresults1.SyncRoot[7]
$sipaport1 = $dnsresults1.syncroot[6]
$siphost = $sipAhost.Split("=")
$sipport = $sipaport.Split("=")
$siphost1 = $sipAhost1.Split("=")
$sipport1 = $sipaport1.Split("=")
$dnscheckhost = $siphost[1].trim()
$dnscheckport = $sipport[1].trim()
$dnscheckhost1 = $siphost1[1].trim()
$dnscheckport1 = $sipport1[1].trim()

Write-Host
Write-Host "The A Record for the Access Edge Host Server is :" $dnscheckhost -ForegroundColor Yellow -BackgroundColor Black
Write-Host "The port we will test for is :" $dnscheckport -ForegroundColor Yellow -BackgroundColor Black
Write-Host
Write-Host "The A Record for the Federation Host Server is :" $dnscheckhost1 -ForegroundColor Yellow -BackgroundColor Black
Write-Host "The port we will test for is :" $dnscheckport1 -ForegroundColor Yellow -BackgroundColor Black

Write-Host
write-host "Testing to see if can ping the Access Edge Server...." -ForegroundColor Green -BackgroundColor Black
pinghost $dnscheckhost
Write-Host
Write-Host "Testing to see if can connect to the Access Edge port...." -ForegroundColor Green -BackgroundColor Black
testtcp $dnscheckhost $dnscheckport
Write-Host

Write-Host
write-host "Testing to see if can ping the Federation Server...." -ForegroundColor Green -BackgroundColor Black
pinghost $dnscheckhost1
Write-Host
Write-Host "Testing to see if can connect to the Federation port...." -ForegroundColor Green -BackgroundColor Black
testtcp $dnscheckhost1 $dnscheckport1
Write-Host

Comments (2)

  1. thomas says:

    Nice tool - good job !

  2. Trey says:

    I'm getting a number of these exceptions:

    You cannot call a method on a null-valued expression.
    At C:Userstyronehdesktoptroubleshoot-signon.ps1:109 char:1
    + $siphost = $sipAhost.Split("=")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:Userstyronehdesktoptroubleshoot-signon.ps1:110 char:1
    + $sipport = $sipaport.Split("=")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:Userstyronehdesktoptroubleshoot-signon.ps1:111 char:1
    + $siphost1 = $sipAhost1.Split("=")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    ...for...

    $siphost = $sipAhost.Split("=")
    $sipport = $sipaport.Split("=")
    $siphost1 = $sipAhost1.Split("=")

Skip to main content