Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Validating service status


One of the first things we learn to do with PowerShell is to inspect the services on a computer. The Get-Service cmdlet with its –ComputerName parameter makes this a simple task. For instance, if we had a list of computers that have SQL Server installed in a variable called $servers, we could issue the following script to get the status of the service running the default instance like this:

Get-service –name MSSQLSERVER –computername $server | 
  Select-object –property Name,Status,MachineName

If our goal was simply to find out whether the service is running, this will do the trick. One piece of information that is missing from the objects output from the Get-Service cmdlet is the name of the account that is used to run the service, the run as account. To find that detail, we must turn to WMI. The class to use is Win32_Service, which contains the StartName property. The value of the StartName property is the name of the user account running the service. To find the...