Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’to type ‘Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup’

In this Azure PowerShell article, we will discuss how to fix the error “New-AzManagementGroup : Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’
to type ‘Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup'” which I got while trying to create a new resource management group in Azure using the New-AzManagementGroup PowerShell command.

Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’ to type’Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup’

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

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

The moment I ran the above PowerShell command, I got the below output.

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 ca n see the same error in the below screen shot.

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

Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’ to type’Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup’ [Solution]

To solve this issue, we need to use the “GroupId” parameter instead of “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 got created successfully in a span of seconds. You can see the output as below.

New-AzManagementGroup

You may also like following the below articles

Conclusion

In this Azure PowerShell article we discussed hot to fix the error “New-AzManagementGroup : Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’ to type ‘Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup’.” Thanks for reading this article !!!