msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Get-MgAgreement - Exception Error when querying the agreements

Open alphasteff opened this issue 2 years ago • 3 comments

Describe the bug When I try to read out the user agreements, an error appears.

To Reproduce Steps to reproduce the behavior:

  1. Install Microsoft.Graph.Identity.Governance (2.10.0 or 2.11.1)
  2. Login: Connect-MgGraph -Scopes "Policy.Read.All", "Policy.ReadWrite.ConditionalAccess" -ErrorAction Stop
  3. Execute from: Get-MgAgreement`

Expected behavior List of existing agreements, including id's.

Debug Output Default Output

ParentContainsErrorRecordException: C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1:2825
Line |
2825 |          $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."

Output of Get-Error

Exception             :
    Type                        : System.Management.Automation.MethodInvocationException
    ErrorRecord                 :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : RuntimeException
        InvocationInfo        :
            ScriptLineNumber : 2825
            OffsetInLine     : 9
            HistoryId        : 32
            ScriptName       : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
            Line             :         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)

            Statement        : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
            PositionMessage  : At C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1:2825 char:9
                               +         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …
                               +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports
            PSCommandPath    : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Get-MgAgreement<Begin>, C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1: line 2825
                                at <ScriptBlock>, <No file>: line 1
    WasThrownFromThrowStatement : True
    TargetSite                  :
        Name          : Invoke
        DeclaringType : System.Management.Automation.Runspaces.PipelineBase, System.Management.Automation, Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message                     : Exception calling "GetSteppablePipeline" with "1" argument(s): "The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object."
    Data                        : System.Collections.ListDictionaryInternal
    InnerException              :
        Type        : System.Management.Automation.RuntimeException
        ErrorRecord :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
                HResult : -2146233087
            CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : BadExpression
            InvocationInfo        :
                ScriptLineNumber : 2824
                OffsetInLine     : 25
                HistoryId        : -1
                ScriptName       : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
                Line             :         $scriptCmd = {& $wrappedCmd @PSBoundParameters}

                Statement        : $wrappedCmd
                PositionMessage  : At C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1:2824 char:25
                                   +         $scriptCmd = {& $wrappedCmd @PSBoundParameters}
                                   +                         ~~~~~~~~~~~
                PSScriptRoot     : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports
                PSCommandPath    : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
                CommandOrigin    : Internal
            ScriptStackTrace      : at Get-MgAgreement<Begin>, C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1: line 2825
                                    at <ScriptBlock>, <No file>: line 1
        TargetSite  :
            Name          : AddCommand
            DeclaringType : System.Management.Automation.PipelineOps, System.Management.Automation, Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message     : The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
        Source      : System.Management.Automation
        HResult     : -2146233087
        StackTrace  :
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.GetSteppablePipeline(PipelineAst pipelineAst, CommandOrigin commandOrigin, ScriptBlock scriptBlock, Object[] args)
   at CallSite.Target(Closure, CallSite, Object, Object)
    Source                      : System.Management.Automation
    HResult                     : -2146233087
    StackTrace                  :
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at Microsoft.PowerShell.Executor.ExecuteCommandHelper(Pipeline tempPipeline, Exception& exceptionThrown, ExecutionOptions options)
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : RuntimeException
InvocationInfo        :
    ScriptLineNumber : 2825
    OffsetInLine     : 9
    HistoryId        : 32
    ScriptName       : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
    Line             :         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)

    Statement        : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
    PositionMessage  : At C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1:2825 char:9
                       +         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …
                       +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports
    PSCommandPath    : C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1
    CommandOrigin    : Internal
ScriptStackTrace      : at Get-MgAgreement<Begin>, C:\Users\xxxxxx\OneDrive - xxxx\Dokumente\PowerShell\Modules\Microsoft.Graph.Identity.Governance\2.11.1\exports\ProxyCmdletDefinitions.ps1: line 2825
                        at <ScriptBlock>, <No file>: line 1

Module Version

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.11.1                Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext…}
Script     2.11.1                Microsoft.Graph.Identity.Governance {Add-MgIdentityGovernanceAccessReviewDefinitionInstanceDecision, Get-MgAgreement, Get-MgAgreementAcceptance, Get-MgAgreementAcceptanceCount…}

Environment Data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

alphasteff avatar Dec 20 '23 08:12 alphasteff

I have tested further, and I get no error message with version PowerShell 5.1.x and the same module version.

alphasteff avatar Dec 20 '23 20:12 alphasteff

Hi @alphasteff, I was able to successfully run the command but only added the "Agreement.ReadWrite.All" scope. image

timayabi2020 avatar Jan 10 '24 11:01 timayabi2020

Just a small update. After some time, I checked everything again and also installed the latest modules. I can no longer reproduce the problem.

alphasteff avatar Feb 20 '24 09:02 alphasteff