Thursday, 27 November 2008

Get-SQLServers.ps1

# Get-SQLServers.ps1
#
Sample showing use of SMO and PowerShell
#
Thomas Lee - tfl@psp.co.uk

# Load the SMO objects
$load = [reflection.assembly]::LoadWithPartialName( "Microsoft.SqlServer.Smo" )

# Derive the SMO Application Object
$smo = [Microsoft.SqlServer.Management.Smo.SmoApplication]

# Get available SQL Servers and display them
$SQLServers = $smo::EnumAvailableSqlServers($false);
"SQL Servers found:"
$SQLServers


This script produces the following output:




PS C:\foo> .\get-sqlservers.ps1
SQL Servers found:


Name : COOKHAM8
Server : COOKHAM8
Instance :
IsClustered : True
Version :
IsLocal : True

Name : SQL001
Server : SQL001
Instance :
IsClustered : True
Version :
IsLocal : False

Name : SQL002
Server : SQL002
Instance :
IsClustered : True
Version :
IsLocal : False

0 comments: