none
Powershell syntax for $MAs = @(get-wmiobject -class "MIIS_ManagementAgent"... RRS feed

  • Question

  • This might be more of a powershell question, but could someone explain this line works:

    $MAs = @(get-wmiobject -class "MIIS_ManagementAgent" -namespace "root\MicrosoftIdentityIntegrationServer" -computername $params_ComputerName)

    I see that $MAs.Count shows 3 agents (in my case) and that I can use $MA[0] through $MA[2] to reference information on each agent, but..

    1.) Is that 'get-wmiobject...' line all one entire command where the results are placed into an array or are we somehow setting each array value with those items? Most examples show @("string", "string") as the means for defining an array.

    2.) Output for one of the array 'items' is

    __GENUS          : 2
    __CLASS          : MIIS_ManagementAgent
    __SUPERCLASS     :
    __DYNASTY        : MIIS_ManagementAgent
    __RELPATH        : MIIS_ManagementAgent.Name="My AD MA"
    __PROPERTY_COUNT : 3
    __DERIVATION     : {}
    __SERVER         : FIMPORTAL
    __NAMESPACE      : root\MicrosoftIdentityIntegrationServer
    __PATH           : \\FIMPORTAL\root\MicrosoftIdentityIntegrationServer:MIIS_M
                       anagementAgent.Name="My AD MA"
    Guid             : {6555D64D-B9DD-44CA-A354-B58821ADB038}
    Name             : My AD MA
    Type             : Active Directory

    Later, in the code presented here: http://social.technet.microsoft.com/Forums/en-US/ilm2/thread/c7e204be-05b4-40e1-bf95-e0191a76ece3

    there is a reference to $MAs which we defined above, but where is $MA defined (without the 's') which is referenced in the for statement => foreach($MA in $MAS) ?

    Thanks!


    • Edited by Osho27 Thursday, December 20, 2012 5:24 PM
    Thursday, December 20, 2012 5:03 PM

Answers

  • The get-wmiObject returns a list of entries from the Class into a list.

    $MAs is a list you can recurse or index through it

    (i.e.

    $MAs | % { $_.Execute("Delta Import") }

    The above will go through each WMI object in the list and invoke the "Execute" method passing the "Delta Import" parameter.

    I believe the call is blocking and synchronous, meaning it won't execute the next line of code until it's complete, the call will also throw an exception if the profile doesn't exist. It will return an object that contains a property called "ReturnValue" in which you can check it's status.

    Friday, December 21, 2012 10:09 PM

All replies

  • Thinking to start simple here, then perhaps work my way to that referenced script.

    If I run $MAs[0].Execute('Delta Import') - how can I confirm that it worked?  Is that the right syntax? Sorry for being lazy here, will check the references now and will post here if I answer my own question.

    Thursday, December 20, 2012 5:54 PM
  • Ok, answered my second post.

    $MAs[1].Execute('Delta Import').ReturnValue

    This returns 'success' if it did so...

    Thursday, December 20, 2012 6:47 PM
  • The get-wmiObject returns a list of entries from the Class into a list.

    $MAs is a list you can recurse or index through it

    (i.e.

    $MAs | % { $_.Execute("Delta Import") }

    The above will go through each WMI object in the list and invoke the "Execute" method passing the "Delta Import" parameter.

    I believe the call is blocking and synchronous, meaning it won't execute the next line of code until it's complete, the call will also throw an exception if the profile doesn't exist. It will return an object that contains a property called "ReturnValue" in which you can check it's status.

    Friday, December 21, 2012 10:09 PM