1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #Install-Module PSWriteColor
cd c:\
$servers=get-content "c:\server.txt"
$query="SELECT servicename,
last_startup_time,
service_account
FROM sys.dm_server_services
where servicename in ('SQL Server (MSSQLSERVER)','Agent SQL Server (MSSQLSERVER)')"
foreach($server in $servers)
{
$results=Invoke-Sqlcmd -ServerInstanc $server -Query $query
foreach($resultat in $results)
{
$resultat| select-object servicename , last_startup_time, service_account |Select-Object -Property @{n="server";e={$server}},servicename , last_startup_time, service_account | Export-Csv -path c:\Server.csv | % {$_.Replace('"','')}
}
} |
Partager