0

I'm running this fairly easy PowerShell command:

az graph query -q "project id, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"

So far so good:

{
  "count": 3,
  "data": [
    {
      "count_": 90,
      "location": "westeurope"
    },
    {
      "count_": 41,
      "location": "eastus"
    },
    {
      "count_": 11,
      "location": "germanywestcentral"
    }
  ],
  "skip_token": null,
  "total_records": 3
}

I want to format the JSON to something more readable so I will use the ConvertFrom-Json option:

az graph query -q "project id, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_" | ConvertFrom-Json

but this results in:

ConvertFrom−Json : The term 'ConvertFrom−Json' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:153
+ ...  summarize count() by location | top 3 by count_"  | ConvertFrom−Json
+                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ConvertFrom−Json:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Why and how to install ConvertFrom−Json?

shouldn't be there by default?

Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113
  • I tried it on my PC, I'm not a PS enthusiast, so it's pretty vanilla. I can run `ConvertFrom-Json` without a problem. – DiMithras Dec 01 '22 at 12:39
  • Could it be that you have some old PS? [Here](https://stackoverflow.com/questions/22256706/running-powershell-script-in-c-sharp-converttojson-error) it's mentioned it should be 3.0+, mine is 5.1.1 – DiMithras Dec 01 '22 at 12:42
  • 1
    Duplicate: [Can't run my script because Powershell read "-" as –](https://stackoverflow.com/a/41447011/1701026)? "*Don't copy commands off websites into a console. Retype them.*" – iRon Dec 01 '22 at 12:54

0 Answers0