none
List all agents from multiple SCOM Management Servers RRS feed

  • Question

  • Hi,

    I wrote following script to list all agents on multiple SCOM Management servers.

    $MgmtServer = Get-SCOMManagementServer | select Displayname |ft -hidetableheaders
    foreach ($Agent in $MgmtServer){ 
    Get-SCOMAgent -ManagementServer $MgmtServer
    }

    Unfortunately I get following error:

    Get-SCOMAgent : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Administration.ManagementServer' required by parameter 'ManagementServer'. Specified
    method is not supported.
    At C:\SCOM_Get_WindowsAgents.ps1:3 char:33
    + Get-SCOMAgent -ManagementServer $MgmtServer
    +                                 ~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-SCOMAgent], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.OperationsManagerV10.Commands.GetSCAgentCom
       mand

    If I write only one Management Server name then script works well.

    How can I list all agents from multiple Management Servers?

    Best regards

    Birdal


    • Edited by _Birdal Tuesday, October 15, 2019 12:59 PM
    Tuesday, October 15, 2019 12:58 PM

Answers

  • Hi Birdal,

    this should work for you (you need to leave the Management Server as an object):

    $MgmtServer = Get-SCOMManagementServer
    foreach ($MServer in $MgmtServer){ 
    Get-SCOMAgent -ManagementServer $MServer
    }

    The logic is:

    - You get all your management servers as objects and your are storing them in the $MgmtServer variable.
    - You then itterate over each management server object and use it to get its agents. 

    In your example you have two innacuracies: 

    1. The first would be getting only the DisplayName of the management server, not the object itself.
    2. The secoind woul be using $Agent in the forach loop, but then using $MgmtServer as value for the "-ManagementServer" parameter. 

    I hope I could help you out. Please don't hesitate to ask if you have more questions. 

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov




    Tuesday, October 15, 2019 1:06 PM
    Moderator

All replies

  • Hi Birdal,

    this should work for you (you need to leave the Management Server as an object):

    $MgmtServer = Get-SCOMManagementServer
    foreach ($MServer in $MgmtServer){ 
    Get-SCOMAgent -ManagementServer $MServer
    }

    The logic is:

    - You get all your management servers as objects and your are storing them in the $MgmtServer variable.
    - You then itterate over each management server object and use it to get its agents. 

    In your example you have two innacuracies: 

    1. The first would be getting only the DisplayName of the management server, not the object itself.
    2. The secoind woul be using $Agent in the forach loop, but then using $MgmtServer as value for the "-ManagementServer" parameter. 

    I hope I could help you out. Please don't hesitate to ask if you have more questions. 

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov




    Tuesday, October 15, 2019 1:06 PM
    Moderator
  • Hi Stoyan,

    Perfect! It worked.

    Thank you also for explanation!

    Best regards

    Birdal

    Tuesday, October 15, 2019 1:22 PM