locked
Power-shell script to install scom agent to multiple servers RRS feed

  • Question

  • Hi

    we are trying to upgrade/install scom 2012 r2 agents to our windows servers (300+) server via powershell script.

    we are wanting the result to be written to csv file but we are facing difficulty in trying to find the object/value to look at to the put the condition against.

    we found the script that does for ping(below part script) result but we want to capture any failure. is there anything we can use to achieve what we ant to do?

    Thank you in Advance.

    -------------------Sample script--------------------------

    # Ping the computer
        $pingStatus = Get-WmiObject -Class Win32_PingStatus -Filter "Address = '$computer'";

        if($pingStatus.StatusCode -eq 0)
        {
            #If computer is up, write message and launch agent install
    InstallSCOMAgent $Computer
    "Success , $computer." | out-file "D:\output.csv" -Append -NoClobber
            
    #Write-Host -ForegroundColor Green  "Reply received from $computer.";
                     
        }
        else
        {
            #Else, just write a message indicating computer unreachable 

           "Failed , $computer." | out-file "D:\output.csv" -Append -NoClobber

        }

    }

    Wednesday, October 8, 2014 5:16 AM

Answers

  • Just in case Newbie like me wondering how it can be done

    Here is the code (of course i got the help) simple but does what i want at this stage.  Next I am looking at how I can push the agents in parallel, this script will take fairly long time when trying to push to huge number of servers.

         

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

    #Import PowerShell Modules 

    import-module OperationsManager


    #Variables

    $InstallAccount = Get-Credential domainname\username
    $PrimaryMgmtServer = Get-SCOMManagementserver -Name <managementservername>


    #Connect to OpsMgr Management Group
    Start-OperationsManagerClientShell -ManagementServerName: <managementservername> -PersistConnection: $true -Interactive: $true;

    $list = Import-Csv -Path 'D:\temp\serverlist.csv'

    foreach ($entry in $list)
        {
    $computer = $entry.ServerName

        try
    {
        Install-SCOMAgent -Name $computer -PrimaryManagementServer $PrimaryMgmtServer -ActionAccount $InstallAccount -ErrorAction Stop
    #Write Success message into file
    "$computer, Success." | out-file "D:\temp\result.csv" -Append -NoClobber
            }

        Catch
    {
    #just write a failure message into file
            "$computer, Failled." | out-file "D:\temp\result.csv" -Append -NoClobber
    }

    }

    --------------------------End---------------------------------------------------------------------------

    • Marked as answer by akg1 Tuesday, November 11, 2014 10:42 AM
    Tuesday, November 11, 2014 10:41 AM

All replies

  • For Deploy agent on Multiple Server, You can use this script by adding Agents names.

    Also you can refer below link for deploy SCOM on multiple Agents

    http://myitforum.com/myitforumwp/2011/11/15/powershell-script-to-install-scom-agent-on-multiple-servers/


    Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer" Mai Ali | My blog: Technical | Twitter: Mai Ali

    Wednesday, October 8, 2014 2:19 PM
  • Hi Mai

    Thanks for reply and I had come across the script you are referring to.

    I am more interested on how do I handle errors and How do I record if agent deployment is succeeded or failed.

    After running the script I need a report showing which server is succeeded and which failed hence my question (may be i didn't explain correctly).

    How do i handle error and record the result of agent deployment?

    Thank you

    Wednesday, October 8, 2014 11:07 PM
  • Hi

    once update/install is started an task is created in the com console for each agent.you can see the result in the task view of the scom server.

    or

    you can start update/install as a job in powershell and you can track the result suing job id.

    Regards


    sridhar v

    Friday, October 10, 2014 9:22 AM
  • Hi Sridhar

    We are looking to deploy agent to 300+ servers so going through Task status in console one by one is not we are wanting to do.

    Tried running script and running job but the output from the job is not consistent.

    Thank you 
    Thursday, October 16, 2014 4:38 AM
  • Just in case Newbie like me wondering how it can be done

    Here is the code (of course i got the help) simple but does what i want at this stage.  Next I am looking at how I can push the agents in parallel, this script will take fairly long time when trying to push to huge number of servers.

         

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

    #Import PowerShell Modules 

    import-module OperationsManager


    #Variables

    $InstallAccount = Get-Credential domainname\username
    $PrimaryMgmtServer = Get-SCOMManagementserver -Name <managementservername>


    #Connect to OpsMgr Management Group
    Start-OperationsManagerClientShell -ManagementServerName: <managementservername> -PersistConnection: $true -Interactive: $true;

    $list = Import-Csv -Path 'D:\temp\serverlist.csv'

    foreach ($entry in $list)
        {
    $computer = $entry.ServerName

        try
    {
        Install-SCOMAgent -Name $computer -PrimaryManagementServer $PrimaryMgmtServer -ActionAccount $InstallAccount -ErrorAction Stop
    #Write Success message into file
    "$computer, Success." | out-file "D:\temp\result.csv" -Append -NoClobber
            }

        Catch
    {
    #just write a failure message into file
            "$computer, Failled." | out-file "D:\temp\result.csv" -Append -NoClobber
    }

    }

    --------------------------End---------------------------------------------------------------------------

    • Marked as answer by akg1 Tuesday, November 11, 2014 10:42 AM
    Tuesday, November 11, 2014 10:41 AM