Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

PowerSQL By Prashanth Jayaram

Technology enthusiast with 7+ years of experience in Database Technology. I am Microsoft Certified Professional with certificates of OCA, MCP, MCTS, MCITP developer, MCITP administration and backed with a degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication, PowerShell and Performance Tuning. Hobbies are Drawing, playing soccer and listening to Melodies songs.

PowerShell – Identify Service Account & Other Details of SQL Services – Multi Server Script

One of my friend requested me to give a mutli server script to pull SQL Service related details. Here is a quick PowerShell script to find Name, ServerName, Status, StartupMode, Service Account and other details of SQL Services across all listed SQL Instances. The output is shown in three different formats.

  • AutoSize
  • HTML
  • CSV

Copy and Paste the below code PowerShell-ISE and execute 

*******************************************************************************

#A PowerShell array holds a list of data items
$Result = @()
#Loop through all SQL Instances listed under F:\PowerSQL\List.txt
foreach($server in Get-Content F:\PowerSQL\List.txt)
{
#List only sql related services, gwmi is an alias of Get-WmiObject
$Services=gwmi win32_service -computername $server | where {$_.Name -like ‘*SQL*’}
#Test for unsuccesful connection
if(!(Test-Connection -Cn $server -BufferSize 16 -Count 1 -ea 0 -quiet))
{“Problem still exists in connecting to $server”}
ELSE {
$services | ForEach {
If ($_)
{ $Result += New-Object PSObject -Property @{
‘Service Display Name’ = $_.Displayname
‘Service Name’ = $_.Name
‘Start Mode’ = $_.Startmode
‘Service Account Name’ = $_.Startname
‘State’ = $_.State
‘Status’= $_.Status
‘System Name’ = $_.Systemname
}
}
}
}
}
$Result |Format-Table -AutoSize

*******************************************************************************

Output:

Image

OR

HTML Format – Change the last line of the code

$Result | ConvertTo-HTML | Out-File F:\PowerSQL\service.htm

OR

CSV File -  Change the last line of the code

$Result |Export-CSV F:\PowerSQL\service.csv


Comments

Leave a comment on the original post [sqlpowershell.wordpress.com, opens in a new window]

Loading comments...