Hi All,
On below code i am passing list of servers but the start time coming only for first server
Please help to resolve.
$Output = @()
$servers = Get-Content “D:\Scripts\servers.txt”
$servers | ForEach {
$Final = Get-WmiObject win32_service -ComputerName $_ -Filter “Name like ‘MSSQLSERVER’ or Name like ‘SQLSERVERAGENT’ or Name like ‘%MSSQL$%’ or Name like ‘%SQLAgent$%’ or Name like ‘ReportServer’
or Name like ‘SQLBrowser’ or Name like ‘MsDtsServer%’” -PipelineVariable Service |
Select-Object -Property @{Name=“Server_Name”;Expression={$.SystemName}}, @{Name=“Service_Name”;Expression={$.Caption}},
@{Name=“Service_Status”;Expression={$.State}}, @{label=‘Start_Time’;expression={(Get-Process -Id $Service.ProcessId).StartTime}},
@{Name=“StartUp_Mode”;Expression={$.StartMode}}, @{Name=“Service_Log_on”;Expression={$.StartName}}
$Output += $Final
}
$Output | Export-CSV "D:\Reports\MSSQL_Service_Status$(get-date -f MM-dd-yyyy).csv" -NoTypeInformation -Encoding UTF8