Powershell Script for checking sql services status and account name
$filename='sql-service-info'
#$directorytosaveto='d:\powershell\fino_daily_check_list\'
$directorytosaveto = 'c:\ps_test\' #split-path -parent $myinvocation.mycommand.path)+'\'
$date = get-date -format "dd_mmm_yyy_hh_mm_tt"
$date2 = get-date -format "dd-mmm-yyy hh:mm tt"
$serverlist = $directorytosaveto+'servers.txt'
$outputfile = $directorytosaveto+$filename+$date+'.html'
$html = '<style type="text/css">
#header{font-family:"trebuchet ms", arial, helvetica, sans-serif;width:100%;border-collapse:collapse;}
#header td, #header th {font-size:14px;border:1px solid #98bf21;padding:3px 7px 2px 7px;}
#header th {font-size:14px;text-align:left;padding-padding-bottom:4px;background-color:#a7c942;color:#fff;}
#header tr.alt td {color:#000;background-color:#eaf2d3;}
</style>'
$html += "<html><body>
<b> sql services information on : $date2</b> <br>
<table border=1 cellpadding=0 cellspacing=0 width=100% id=header><tr><th>server name</th><th>service name</th><th>start mode</th><th>by account</th><th>current state</th><th>name</th></tr>"
if (!(test-path -path "$directorytosaveto")) #create if not existing
{
new-item "$directorytosaveto" -type directory | out-null
}
foreach ($serverip in get-content $serverlist) {
$table=get-wmiobject win32_service -computername $serverip | where-object {$_.displayname -like 'sql server (*'} | select displayname,name,startmode,startname, state
$table | foreach-object {
$html += "<tr ><td>"+$serverip +"</td><td>"+$_.displayname +"</td><td>"+$_.startmode +"</td><td>"+$_.startname +"</td><td>"+$_.state+"</td><td>"+$_.name+"</td> </tr>"
}
$ip=0
}
$date='_'+$date
$html += "</table></body></html>"
$html | out-file $outputfile
write-host $outputfile
SQL Server > SQL Server Search
Comments
Post a Comment