Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type

In this Azure PowerShell article, we will discuss how to fix the error “unable to cast object of type ‘newtonsoft.json.linq.jvalue’ to type ‘newtonsoft.json.linq.jobject'” which I got while trying to create a new resource management group in Azure using the New-AzManagementGroup PowerShell command.

I had a requirement to create an Azure management group using the New-AzManagementGroup command. So, I was trying to execute the below PowerShell command.

PS C:\WINDOWS\system32> New-AzManagementGroup -GroupName "TsinfoGroup"

I got the below output when I ran the above PowerShell command.

New-AzManagementGroup : Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' 
to type 'Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup'.
At line:1 char:1
+ New-AzManagementGroup -GroupName "TsinfoGroup"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzManagementGroup], InvalidCastExc 
   eption
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.ManagementGroups.New 
   AzureRmManagementGroup

You can see the same error in the below screenshot.

unable to cast object of type 'newtonsoft.json.linq.jvalue' to type 'newtonsoft.json.linq.jobject'

Solution

To solve this issue, we need to use the “GroupId” parameter instead of the “GroupName” parameter. So, we need to execute the below PowerShell script to create the management group in Azure.

PS C:\WINDOWS\system32> New-AzManagementGroup -GroupId "TsinfoGroup"

After executing the above command, I got the correct output, and the management group was created successfully in seconds. You can see the output in the screenshot below.

unable to cast object of type 'newtonsoft.json.linq.jvalue' to type 'newtonsoft.json.linq.jobject'.

You may also like following the articles below

Conclusion

In this Azure PowerShell article, we discussed how to fix the error unable to cast object of type ‘newtonsoft.json.linq.jvalue’ to type ‘newtonsoft.json.linq.jobject.Thanks for reading this article !!!

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!