Book Image

PowerShell for SQL Server Essentials

By : Donabel Santos
Book Image

PowerShell for SQL Server Essentials

By: Donabel Santos

Overview of this book

Table of Contents (15 chapters)
PowerShell for SQL Server Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Implementing Reusability with Functions and Modules
Index

Current SQL Server instances


You should also check how many SQL Server instances are installed on the server and their names for non-default instances. To do this, we can use SQL Management Objects (SMO) with PowerShell and then use the ServerInstances member property:

#below should be a single line of code
$managedComputer = New-Object "Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer" $servername

#list SQL Server instances
$managedComputer.ServerInstances |
Select-Object Name, State, ServerProtocols, Urn |
Format-List

The preceding script simply lists the instances installed. Note that MSSQLSERVER is the name you'll see for a default instance: