Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Discovering SQL Server services


In this recipe, we will enumerate all SQL Server services and list their statuses.

Getting ready

Check which SQL Server services are installed in your instance. Go to Start | Run and type services.msc. You should see a screen similar to this:

How to do it...

Let's assume you are running this script on the server box:

  1. Open PowerShell ISE as administrator.

  2. Add the following code and execute:

    Import-Module SQLPS -DisableNameChecking
    
    #you can replace localhost with your instance name
    $instanceName = "localhost"
    $managedComputer = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $instanceName
    
    #list services
    $managedComputer.Services |
    Select-Object Name, Type, ServiceState, DisplayName |
    Format-Table -AutoSize

    Your result will look similar to the one shown in the following screenshot:

    Items listed in your screen will vary depending on the features installed and running in your instance

  3. Confirm that these are the services that exist in your server. Check...