Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Powershell script to capture SQL service status Expand / Collapse
Author
Message
Posted Tuesday, August 27, 2013 8:19 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 1:38 PM
Points: 221, Visits: 1,129
Hello everyone
Can anyone offer some advice on how I would capture SQL server services, i.e started etc for each SQL instance in a .txt file containing the servers I want to look at ?
One issue I have is that I need to use SQL authentication to connect to the boxes as they are across different domains.

Any tips or help greatly appreciated.

All I want is a list exported to excel , Server name , SQL Service status etc.

Many thanks for any advice.
Post #1488800
Posted Wednesday, August 28, 2013 6:23 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 5:48 AM
Points: 428, Visits: 927
A web search using the words "Services Powershell Status" leads to the following:

get-service -name "MSSQLServer" -Computername TargetServerName

Which returns

Status Name DisplayName
------ ---- -----------
Running MSSQLServer SQL Server (MSSQLSERVER)

For named instances, the format is MSSQLServer$instancename




Post #1489161
Posted Wednesday, August 28, 2013 7:10 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 1:38 PM
Points: 221, Visits: 1,129
[quote]schleep (8/28/2013)
A web search using the words "Services Powershell Status" leads to the following:

get-service -name "MSSQLServer" -Computername TargetServerName

Which returns

Status Name DisplayName
------ ---- -----------
Running MSSQLServer SQL Server (MSSQLSERVER)

For named instances, the format is MSSQLServer$instancename

Thank you for your reply.
I get the error : This operation might require other privileges when I try to connect with SQL authentication in place.
It works fine when I try on my local machine for 1 instance where I know my AD permission has the required privs.
I need to connect with SQL authentication as I am trying to go cross domains.

Post #1489189
Posted Wednesday, August 28, 2013 8:03 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Today @ 5:48 AM
Points: 428, Visits: 927
Some definitions appear to be in order:
machine = the physical / virtual server on which an instance of SQL Server is installed.
SQL Server = software that runs on a machine. There can be one or more instances of SQL Server installed on a machine.

For what you're trying to accomplish, you need permissions to
1) connect to the machines running the SQL Server services
2) view the status of services running on those machines.

If you don't have 1), it's all over. Even if you do have 1), you may not have 2): that will be up to your sysadmin.

At no point do you need to login to any SQL Server: this has nothing to do with SQL Authentication whatsoever. You can have an SQL Login and DB access on a SQL Server, but without the rights to connect to the machine running that SQL Server, well, you won't get in. Also, even if you are allowed to connect to the machine, if the SQL Server service is not started, your SQL Authentication will fail.

You'll need to use the Get-WmiObject instead, it allows you to pass credentials. You can look it up.

Get-WmiObject win32_service -comp "ServerName" | select __server,name,startmode,state,status





Post #1489238
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse