find the status of SQL Services on multiple servers

  • I have a scenario where our DBAs and Server team planned for Maintenance, tonight.

    We have more than 800 servers that are to be rebooted.

    Is there any way, I can check the status of SQL Server and Agent Services, 'running', 'stopped', 'disabled', 'manual', 'if clustered', 'time started' on all multiple servers at a time ?

    I would like to have a script towards it, if I can provide a servers list into text and then the output pumped to text or excel file.

    Please help and thanks in advance.

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • Found something, but only for one and it is also not accurate.. Any help is appreciated.

    $servers=get-content "D:\instances.txt"

    foreach($server in $servers)

    { get-wmiobject win32_service -computername $server |

    select name,state |

    where {

    ($_.name -like "SQLAGENT*" -or $_.name -like "SQL*AGENT" ) `

    -and $_.state -match "Stopped"} | Out-String

    }

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • any help is appreciated..

    the below script gives report to only one machine twice when it is ran through VM.

    List of servers are not getting used for checking.

    why script not trying next server names in the list other than local instance.

    it results for local machine only. I would like to pull details of

    1. SQL Server & SQL Server Agent services, started and stopped.

    2. If stopped, start them automatically.

    3. again check for status.

    I am trying for 3 steps handy and verified after maintenance..

    ----------------------------------------------------------------------------------------------------------------------------

    #create final results to export

    $results = @()

    # Defining output format for each column.

    $fmtName =@{label="Service Name" ;alignment="left" ;width=30 ;Expression={$_.Name};};

    $fmtMode =@{label="Start Mode" ;alignment="left" ;width=10 ;Expression={$_.StartMode};};

    $fmtState =@{label="State" ;alignment="left" ;width=10 ;Expression={$_.State};};

    $fmtStatus =@{label="Status" ;alignment="left" ;width=10 ;Expression={$_.Status};};

    $fmtMsg =@{label="Message" ;alignment="left" ;width=50 ; `

    Expression={ if (($_.StartMode -eq "Auto") -and ($_.State -ne "Running") ) {"Alarm: Stopped"} };};

    foreach ($svr in Get-Content "C:\SQLinstances.txt")

    {

    $srvc = Get-WmiObject `

    -query "SELECT *

    FROM win32_service

    WHERE name LIKE '%SQL%'

    OR name LIKE '%MSOLAP%'

    OR name LIKE '%ReportServer%'

    OR name LIKE '%MSDtsServer%'" `

    -computername $server `

    | Sort-Object -property name;

    Write-Output ("Server: {0}" -f $server);

    Write-Output $srvc | Format-Table $fmtName, $fmtMode, $fmtState, $fmtStatus, $fmtMsg;

    }

    $results | Export-Csv -Path C:\results.csv

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • Appreciate if anyone can help.

    ---- ONe more add on.

    I have SQL 2000, 2005, 2008, R2 & 2012 in place, of 800+ servers.

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • Hi,

    have you kept the firewall settings in mind. Have you allowed the remote powershell ports?

    http://blogs.technet.com/b/christwe/archive/2012/06/20/what-port-does-powershell-remoting-use.aspx

    Another possibility to check the running server:

    You can use the Registered Servers feature of the SSMS. Generate a serverlist to import and start a new query. All server without connection would be listed in the messages window.

    [font="Arial"]Kind regards,

    Patrick Fiedler
    Consultant

    Fiedler SQL Consulting

    www.fiedler-sql-consulting.de
    [/font]

  • yes we are using Powershell already for all the machines.

    But I am to trying to get this done by SQL Queries.

    Is there any way to add all the servers to "Central Management Servers".

    One by one registering will take long time for me to register lot number of SQL servers.

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • Hi,

    With registered Servers it could be ok. Add two Server to the registered Server, Export it and try to generate the XML with select on the Server list. And Then try Import it.

    [font="Arial"]Kind regards,

    Patrick Fiedler
    Consultant

    Fiedler SQL Consulting

    www.fiedler-sql-consulting.de
    [/font]

  • Thanks Patrick for your time.

    Adding 800+ servers to "Central Management Servers" is a big problem and in manual.

    Any automation for this to register.

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"

  • Here'a a couple of what sounds like a decent tool I found in 10 minutes using my assistant DBA, Google. 😛

    I like this first one the most because I can call Powershell from xp_CmdShell (captures the result set directly) or just run Powershell separately and pipe the output to an importable file.

    http://www.mssqltips.com/sqlservertip/2013/find-sql-server-instances-across-your-network-using-windows-powershell/

    Here's another that goes above and beyond.

    http://www.straightpathsql.com/archives/2009/02/what-sql-instances-are-installed-on-my-network/

    http://www.microsoft.com/en-us/download/details.aspx?id=7826

    MAP (Microsoft Assessment and Planning Toolkit) (from the links above) supposedly makes a spreadsheet and a word document with all the goodies you might care to lookup.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This should do what you need. If it doesn't work, I wonder if there may be some firewall policy or server security blocking you.

    gwmi win32_service -comp (gc servers.txt) |

    select __server,name,startmode,state,status

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply