PowerShell - Getting All Running SQL Services

ben himself's picture

Getting all SQL Server services running on a server using PowerShell:

Get-WmiObject -Class sqlservice -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement11" | Select ServiceName

Additionally, this can be set to an array and worked with as such.

$services = Get-WmiObject -Class sqlservice -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement11" | Select ServiceName

foreach($service in $services)
{
    $service.ServiceName
}

$services[0].ServiceName
>> MSSQLSERVER

$services[1].ServiceName
>> SQLBrowser

$services[2].ServiceName
>> SQLSERVERAGENT

Tags: 

Categories: