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.
Table of Contents
Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type
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 ca n see the same error in the below screen shot.
Unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type [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.
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 !!!
I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.