Wednesday, October 16, 2013

Lync Server Test Drive–Discovering SQL Servers

In a recent blog article, I wrote about the Lync Server Test Drive Virtual Machines that Microsoft had put up for use. This is a huge set of VMs, but it all does work. With the VMs up and running, I can now begin to write some scripts against this VM set.

Today’s script, Get-SQLServer2.ps1 uses the SQL Server SQL Management Objects (SMOs) to discover the SQL instances in use on the network (the subnet used by the Test Drive set). The link points you toward the  actual script which you can download and use!

The core of the script is accomplished by one line:


This statement used the SMOs to enumerate the instances of SQL on the local net. However, $SQLServers is returned not as an array but as a Data Table containing Data Rows (one per instance). So in order to convert this back to being AN array of Data rows, I use this logic:

$Srvs = @()
Foreach ($srv in $SQLServers) {
$srvs += $srv

Once I have these instances in an array, I can print them out like this:

"There are {0} SQL Server(s) on the Local Subnet" -f $Srvs.count
$Srvs | Select ServerName, InstanceName, Version | Format-Table -AutoSize

So as you can see from the output, there are a total of 7 instances of SQL server in the Test Drive network.

The joys of PowerShell and SMOs. I’ll be both documenting SMOs more here as well as diving down into the Lync Databases in coming articles.


No comments: