• any help is appreciated..

    the below script gives report to only one machine twice when it is ran through VM.

    List of servers are not getting used for checking.

    why script not trying next server names in the list other than local instance.

    it results for local machine only. I would like to pull details of

    1. SQL Server & SQL Server Agent services, started and stopped.

    2. If stopped, start them automatically.

    3. again check for status.

    I am trying for 3 steps handy and verified after maintenance..

    ----------------------------------------------------------------------------------------------------------------------------

    #create final results to export

    $results = @()

    # Defining output format for each column.

    $fmtName =@{label="Service Name" ;alignment="left" ;width=30 ;Expression={$_.Name};};

    $fmtMode =@{label="Start Mode" ;alignment="left" ;width=10 ;Expression={$_.StartMode};};

    $fmtState =@{label="State" ;alignment="left" ;width=10 ;Expression={$_.State};};

    $fmtStatus =@{label="Status" ;alignment="left" ;width=10 ;Expression={$_.Status};};

    $fmtMsg =@{label="Message" ;alignment="left" ;width=50 ; `

    Expression={ if (($_.StartMode -eq "Auto") -and ($_.State -ne "Running") ) {"Alarm: Stopped"} };};

    foreach ($svr in Get-Content "C:\SQLinstances.txt")

    {

    $srvc = Get-WmiObject `

    -query "SELECT *

    FROM win32_service

    WHERE name LIKE '%SQL%'

    OR name LIKE '%MSOLAP%'

    OR name LIKE '%ReportServer%'

    OR name LIKE '%MSDtsServer%'" `

    -computername $server `

    | Sort-Object -property name;

    Write-Output ("Server: {0}" -f $server);

    Write-Output $srvc | Format-Table $fmtName, $fmtMode, $fmtState, $fmtStatus, $fmtMsg;

    }

    $results | Export-Csv -Path C:\results.csv

    Cheers,
    - Win
    "Dont Judge a Book by its Cover"