Looking for Powershell Expert

  • Hi,

    i am looking to find powershell expert, so that can help on my query.below script does return sql installed services on server but it will not return anything if service is not installed. my requirement to return wheather service is running then 'running' else 'not installed or not running'. can anyone please help me.

    # Configuration data.

    # Add your machine names to check for to the list:

    [Array] $servers = "server name";

    # 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($server in $servers)

    {

    $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;

    }

    thanks

  • Duplicate post. Direct replies here. http://www.sqlservercentral.com/Forums/Topic1494563-1550-1.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply