SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell script to capture SQL service status


Powershell script to capture SQL service status

Author
Message
MickyD
MickyD
SSC-Addicted
SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)

Group: General Forum Members
Points: 454 Visits: 1500
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.
schleep
schleep
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1028 Visits: 1328
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



MickyD
MickyD
SSC-Addicted
SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)SSC-Addicted (454 reputation)

Group: General Forum Members
Points: 454 Visits: 1500
[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.
schleep
schleep
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1028 Visits: 1328
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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search