Catch: this lists any service that has “SQL” in it, so can potentially list MySQL services too :)

ListAll SQL services


#list stopped SQL Server services
$computername = "APHRODITE"
Get-WmiObject win32_service -computername $computername |
select name, state |
where {
   ($_.name -like "SQLAGENT*" -or $_.name -like "*SQL*") `
    }

Another way to do this:

#note ComputerManagement works on SQL Server 2005
#on SQL Server 2008 this has to be ComputerManagement10
Get-WmiObject `
-namespace root\Microsoft\SqlServer\ComputerManagement `
-class SqlService | Select-Object ServiceName, DisplayName, SQLServiceType, State

List Stopped SQL services


#list stopped SQL Server services
$computername = "APHRODITE"
Get-WmiObject win32_service -computername $computername |
select name, state |
where {
   ($_.name -like "SQLAGENT*" -or $_.Name -like "*SQL*") `
    -and $_.State -match "Stopped"
    }

List Running SQL services


#list stopped SQL Server services
$computername = "APHRODITE"
Get-WmiObject win32_service -computername $computername |
select name, state |
where {
   ($_.name -like "SQLAGENT*" -or $_.Name -like "*SQL*") `
    -and $_.State -match "Stopped"
    }
VN:F [1.4.0_681]
Rating: 9.7/10 (3 votes cast)
Share :
  • Digg
  • del.icio.us
  • Google
  • description
  • StumbleUpon
  • Technorati
  • TwitThis

Related posts:

  1. SQL Server PowerShell : Search for SQL Server Objects Using PowerShell ...
  2. SQL Server PowerShell : How to Audit Your SQL Server Instance Properties Using PowerShell and SMO ...
  3. Creating Reports From SharePoint Lists Using SQL Server Reporting Services (SSRS) ...
  4. SQL Server 2008 Reporting Services Book Shelf ...
  5. SQL Server PowerShell : How to Backup SQL Server Databases Using SMO and PowerShell ...
  6. List all ASCII characters ...