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

Services and service accounts


Once you have identified the instances, you may want to know the SQL Server-related services for each one of the instances. You can use the same SMO class to query the services related to a SQL Server instance. The Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer class has a property called Services that lists the services:

Import-Module SQLPS -DisableNameChecking

#current server name
$servername = "ROGUE"

$managedComputer = New-Object "Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer" $servername

$managedComputer.Services |
Select-Object Name, ServiceAccount, DisplayName |
Format-Table -AutoSize

You should see a result similar to the following screenshot:

You can see that in my instance, I have many services installed, including SQL Server Agent, SQL Server Integration Services, SQL Server Analysis Services, and SQL Server Reporting Services.