PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
44.57k stars 7.2k forks source link

Issue Calling Get-MgUser and Get-MgGroup #20707

Open JNichNP opened 9 months ago

JNichNP commented 9 months ago

Prerequisites

Steps to reproduce

When I Connect-MgGraph, and try to use Get-MgUser or Get-MgGroup, I get the same error:

ParentContainsErrorRecordException: C:\Program Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1:15863

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."

Downgraded to 7.3.9 And Get-MgUser and Get-MgGroup work as expected.

Expected behavior

PS C:\Program Files\PowerShell\7> Get-MgUser

DisplayName            Id                                   Mail                                 UserPrincipalName
-----------            --                                   ----                                 -----------------

Actual behavior

ParentContainsErrorRecordException: C:\Program Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1:15863
 Line |
15863 |          $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."

Error details

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 : 15863
            OffsetInLine     : 9
            HistoryId        : 2
            ScriptName       : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
            Line             :         $steppablePipeline =
$scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)

            Statement        : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
            PositionMessage  : At C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1:15863 char:9
                               +         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …
                               +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Program Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports
            PSCommandPath    : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
            CommandOrigin    : Internal
        ScriptStackTrace      : at Get-MgUser<Begin>, C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1: line 15863
                                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 : 15862
                OffsetInLine     : 25
                HistoryId        : -1
                ScriptName       : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
                Line             :         $scriptCmd = {& $wrappedCmd @PSBoundParameters}

                Statement        : $wrappedCmd
                PositionMessage  : At C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1:15862 char:25
                                   +         $scriptCmd = {& $wrappedCmd @PSBoundParameters}
                                   +                         ~~~~~~~~~~~
                PSScriptRoot     : C:\Program Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports
                PSCommandPath    : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
                CommandOrigin    : Internal
            ScriptStackTrace      : at Get-MgUser<Begin>, C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1: line 15863
                                    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 : 15863
    OffsetInLine     : 9
    HistoryId        : 2
    ScriptName       : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
    Line             :         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)

    Statement        : $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
    PositionMessage  : At C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1:15863 char:9
                       +         $steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvoc …
                       +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Program Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports
    PSCommandPath    : C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1
    CommandOrigin    : Internal
ScriptStackTrace      : at Get-MgUser<Begin>, C:\Program
Files\PowerShell\Modules\Microsoft.Graph.Users\2.9.0\exports\ProxyCmdletDefinitions.ps1: line 15863
                        at <ScriptBlock>, <No file>: line 1

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

Visuals

No response

Mirandur commented 9 months ago

I get the exact same error in 7.4.0, using the version installed from Microsoft Store. Using 4.3.10 installed from MSI, it works as expected. I have not tried 7.4.0 installed from MSI yet. See attached screenshot.

OS: Windows 10.0.19045 Enterprise Build 19045 Mg-Graph ver. 2.9.1 installed from PSGallery in Windows PowerShell 5 environment.

mggraph error

Mirandur commented 9 months ago

The issue is resolved for get-mguser using Mg-Graph module version 2.10.0 released earlier today. get-mggroup still gives the same error. Thus this seems to be a module compatibility problem and not a PowerShell 7.4 problem.

(Edit: corrected mistakes)

Mirandur commented 9 months ago

The issue is resolved for get-mguser using Mg-Graph module version 2.10.0 released earlier today. get-mggroup still gives the same error. Thus this seems to be a module compatibility problem and not a PowerShell 7.4 problem.

(Edit: corrected mistakes)

Seems I was mistaken, see thread in https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2460. Apparently, this error is related to an experimental feature (WDAC) in PowerShell 7.4.0. The related issue https://github.com/PowerShell/PowerShell/issues/20785 has been classified as a bug.