Blog Post

Powershell One Liners: Get status of SQL Instances on All SQL Servers

,

# Assuming you have list of servers in servers.txt, each sever name in its own line

$ComputerNames = get-content servers.txt

Get-WmiObject -Query "select * from win32_service where PathName like '%%sqlservr.exe%%'"  -ComputerName $ComputerNames | ft -Property PSComputerName, @{Name = "ServiceName"; Expression = 'Name'}, PathName, ExitCode, ProcessID, StartMode, State, Status

# To export the output into an excel/csv, just add "export-csv <filename.csv>" at the end..
Get-WmiObject -Query "select * from win32_service where PathName like '%%sqlservr.exe%%'"  -ComputerName $ComputerNames | ft -Property PSComputerName, @{Name = "ServiceName"; Expression = 'Name'}, PathName, ExitCode, ProcessID, StartMode, State, Status | export-csv SQLInstancesStatus.csv






PS: Or, to make this a true one-liner, embed the get-content cmdlet inside rounded brackets



Get-WmiObject -Query "select * from win32_service where PathName like '%%sqlservr.exe%%'"  -ComputerName (get-content servers.txt) | ft -Property PSComputerName, @{Name = "ServiceName"; Expression = 'Name'}, PathName, ExitCode, ProcessID, StartMode, State, Status


Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating