none
Help with PowerShell function to execute managment agent run profiles. RRS feed

  • Question

  • I call the function like so:

    Start_RunProfile($AD,$FI)

    Output looks like this:

      is executing  (Values for $CMA and $RP are null?)
    You cannot call a method on a null-valued expression.
    At line:28 char:12
    +     return $CMA.Execute($RP).ReturnValue
    +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    #- - - - - - - - - - - - - Functions - - - - - - - - - - - - -
    #Function to execute Run Profile of specified MA
    #Run Profile $RP in $MA agent  
    function Start_RunProfile($MA,$RP)
        {
        $CMA = (get-wmiobject -class "MIIS_ManagementAgent" -namespace "root\MicrosoftIdentityIntegrationServer" -filter "Name='$MA'")
        Write-Host $CMA.Name $RP "is executing"
        return $CMA.Execute($RP).ReturnValue                    
        }
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    But if I run the 3 lines of the function directly it executes as expected.

    $CMA = (get-wmiobject -class "MIIS_ManagementAgent" -namespace "root\MicrosoftIdentityIntegrationServer" -filter "Name='$MA'")
        Write-Host $CMA.Name $RP "is executing"
        return $CMA.Execute($RP).ReturnValue  

    Output looks like this:
    ADMA FullImport is executing
    success

    Why does it fail when I call it as a function?


    • Edited by R Kirchhof Monday, February 25, 2019 5:08 PM
    Monday, February 25, 2019 4:58 PM

All replies