Wednesday, 16 October 2013

Get-SQLServer2.ps1

  1. #Requires -Version 3.0 
  2. <# 
  3. .SYNOPSIS 
  4.     This script Gets a list of SQL Severs on the Subnet 
  5. .DESCRIPTION 
  6.     This script uses SMO to Find all the local SQL Servers  
  7.     and displays them 
  8.  
  9. .NOTES 
  10.     File Name  : Get-SQLServer2.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 3.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.     PS>  # On a Lync Server looking at Lync Implementation 
  18.     PS>  Get-SQLServer2 
  19.     There are 7 SQL Server(s) on the Local Subnet 
  20.  
  21.     ServerName      InstanceName Version      
  22.     ----------      ------------ -------      
  23.     2013-LYNC-MGT   MON          10.50.2500.0 
  24.     2013-LYNC-MGT   SCOM         10.50.2500.0 
  25.     2013-TS         RTCLOCAL     11.0.2100.60 
  26.     2013-SHAREPOINT SPSDB        11.0.3000.0  
  27.     2013-LYNC-FE    RTC          11.0.2100.60 
  28.     2013-LYNC-FE    RTCLOCAL     11.0.2100.60 
  29.     2013-LYNC-FE    LYNCLOCAL    11.0.2100.60 
  30.      
  31. #> 
  32. Import-Module SQLPS 
  33.  
  34. # Now get all the database servers on the local subnet 
  35.  
  36. $SQLservers = [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources() 
  37. $Srvs= @() 
  38.  
  39. # Convert collection to an array 
  40. Foreach ($srv in $SQLservers) { 
  41. $srvs += $srv 
  42.  
  43. # Now display results 
  44. If ($Srvs.count -LE 0) { 
  45. "There are no SQL Servers on the Local Subnet" 
  46. return
  47.  
  48. # Now print server details 
  49. "There are {0} SQL Server(s) on the Local Subnet" -f $Srvs.count 
  50. $Srvs | Select ServerName, InstanceName, Version | Format-Table -AutoSize 

No comments: