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

Find-MgGraphCommand failing when Powershell ISE is running under Administrator context

Open jrocek opened this issue 2 years ago • 0 comments

Describe the bug

If I run Powershell ISE as Administrator (different user than one logged into the system), command Find-MgGraphCommand will throw an error. If run command in ISE which is running under user context it will show me correct result

Error: Find-MgGraphCommand : System.Management.Automation.MethodInvocationException: Exception calling "ConvertFromJson" with "4" argument(s): "Specified argument was out of the range of valid values. Parameter name: value" ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value at Newtonsoft.Json.JsonSerializer.set_MetadataPropertyHandling(MetadataPropertyHandling value) at Newtonsoft.Json.JsonSerializer.ApplySerializerSettings(JsonSerializer serializer, JsonSerializerSettings settings) at Newtonsoft.Json.JsonSerializer.CreateDefault(JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Microsoft.Graph.PowerShell.Authentication.Helpers.StringUtil.ConvertFromJson(String jsonString, Boolean returnHashtable, Nullable1 maxDepth, ErrorRecord& error) at CallSite.Target(Closure , CallSite , Type , Object , Boolean , Int32 , PSReference ) --- End of inner exception stack trace --- at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess) at System.Management.Automation.PSScriptCmdlet.DoEndProcessing() at System.Management.Automation.CommandProcessorBase.Complete() At line:1 char:1

  • Find-MgGraphCommand -command get-mguserlicensedetail
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Find-MgGraphCommand
    
    

To Reproduce Steps to reproduce the behavior:

  1. Run Powershell ISE as Administrator (different account than logged into system)
  2. Run command Find-MgGraphCommand -command get-mguser

Expected behavior

I expected to get following output

APIVersion: v1.0

Command Module Method URI OutputType Permissions


Get-MgUser Users GET /users/{user-id} IMicrosoftGraphUser {DeviceManagementApps.Read.All, DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.Read.A... Get-MgUser Users GET /users IMicrosoftGraphUser {DeviceManagementApps.Read.All, DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.Read.A...

Debug Output DEBUG: Reading MgCommandMetadata from session object. DEBUG: Received Command: get-mguser DEBUG: Reading MgLegacyCommandMapping from file path - C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Authentication\2.6.1\custom\common\MgLegacyCommandMapping.json. Find-MgGraphCommand : System.Management.Automation.MethodInvocationException: Exception calling "ConvertFromJson" with "4" argument(s): "Specified argument was out of the range of valid values. Parameter name: value" ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value at Newtonsoft.Json.JsonSerializer.set_MetadataPropertyHandling(MetadataPropertyHandling value) at Newtonsoft.Json.JsonSerializer.ApplySerializerSettings(JsonSerializer serializer, JsonSerializerSettings settings) at Newtonsoft.Json.JsonSerializer.CreateDefault(JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Microsoft.Graph.PowerShell.Authentication.Helpers.StringUtil.ConvertFromJson(String jsonString, Boolean returnHashtable, Nullable1 maxDepth, ErrorRecord& error) at CallSite.Target(Closure , CallSite , Type , Object , Boolean , Int32 , PSReference ) --- End of inner exception stack trace --- at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess) at System.Management.Automation.PSScriptCmdlet.DoEndProcessing() at System.Management.Automation.CommandProcessorBase.Complete() At line:1 char:1

  • Find-MgGraphCommand -command get-mguser -debug
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Find-MgGraphCommand
    
    

Module Version ModuleType Version Name ExportedCommands


Script 2.6.1 Microsoft.Graph.Applications {Add-MgApplicationKey, Add-MgApplicationPassword, Add-MgServicePrincipalKey, Add-MgServicePrincipalPassword...}
Script 2.6.1 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...}
Script 2.6.1 Microsoft.Graph.DeviceManagement... {Get-MgDeviceManagementConditionalAccessSetting, Get-MgDeviceManagementDeviceEnrollmentConfiguration, Get-MgDeviceManagementDevic... Script 2.6.1 Microsoft.Graph.DeviceManagement... {Confirm-MgDeviceManagementWindowsEnrollmentAutoDiscovery, Get-MgDeviceManagementAuditEventAuditActivityType, Get-MgDeviceManagem... Script 2.6.1 Microsoft.Graph.Devices.CloudPrint {Get-MgPrint, Get-MgPrintConnector, Get-MgPrintConnectorCount, Get-MgPrintOperation...}
Script 2.6.1 Microsoft.Graph.Devices.Corporat... {Get-MgDeviceAppManagement, Get-MgDeviceAppManagementAndroidManagedAppProtection, Get-MgDeviceAppManagementAndroidManagedAppProte... Script 2.6.1 Microsoft.Graph.DirectoryObjects {Confirm-MgDirectoryObjectMemberGroup, Confirm-MgDirectoryObjectMemberObject, Get-MgDirectoryObject, Get-MgDirectoryObjectAvailab... Script 2.6.1 Microsoft.Graph.Education {Get-MgEducationClass, Get-MgEducationClassAssignment, Get-MgEducationClassAssignmentCategory, Get-MgEducationClassAssignmentCate... Script 2.6.1 Microsoft.Graph.Files {Add-MgDriveListContentTypeCopy, Add-MgDriveListContentTypeCopyFromContentTypeHub, Add-MgShareListContentTypeCopy, Add-MgShareLis... Script 2.6.1 Microsoft.Graph.Mail {Get-MgUserInferenceClassification, Get-MgUserInferenceClassificationOverride, Get-MgUserInferenceClassificationOverrideCount, Ge... Script 2.6.1 Microsoft.Graph.People {Get-MgUserLastSharedMethodInsight, Get-MgUserPerson, Get-MgUserPersonCount, Get-MgUserSharedCountInsight...}
Script 2.6.1 Microsoft.Graph.Security {Add-MgSecurityCaseEdiscoveryCaseCustodianHold, Add-MgSecurityCaseEdiscoveryCaseNoncustodialDataSourceHold, Add-MgSecurityCaseEdi... Script 2.6.1 Microsoft.Graph.Sites {Add-MgSite, Add-MgSiteContentTypeCopy, Add-MgSiteContentTypeCopyFromContentTypeHub, Add-MgSiteListContentTypeCopy...}
Script 2.6.1 Microsoft.Graph.Teams {Add-MgChatMember, Add-MgTeamChannelMember, Add-MgTeamMember, Add-MgTeamPrimaryChannelMember...}
Script 2.6.1 Microsoft.Graph.Users {Get-MgUser, Get-MgUserCount, Get-MgUserCreatedObject, Get-MgUserCreatedObjectAsServicePrincipal...}
Script 2.6.1 Microsoft.Graph.Users.Actions {Add-MgUserChatMember, Add-MgUserDriveListContentTypeCopy, Add-MgUserDriveListContentTypeCopyFromContentTypeHub, Clear-MgUserChat... Script 2.6.1 Microsoft.Graph.Users.Functions {Export-MgUserDeviceAndAppManagementData, Get-MgAllUserChatMessage, Get-MgUserCalendarEventDelta, Get-MgUserChatMessageDelta...}

Environment Data Name Value


PSVersion 5.1.22621.1778
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.1778
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

I need to be able to work with powershell graph module even when I am running ISE/console under Administrator as I need to get data from on-prem AD and work with those with in Microsoft.Graph - for example licensing and delicensing users based on OU.

jrocek avatar Sep 26 '23 12:09 jrocek