title: how do you select just one property from an array of "results" from the Azure command 'az group list in powershell'?
body: <p>I am trying to select just one property from an array of "result" (objects?) which come back from the Azure command <code>az group list</code> in powershell? </p>
  
  <p>I know this sounds trivial, but here's where it gets strange, and I hope there is a simple explanation.</p>
  
  <p>If I run the Azure command <code>az group list -o table</code> (after I have succesfully logged in using <code>az login</code>) I get the following typical response</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS src&gt; az group list -o table             
  Name              Location    Status
  ----------------  ----------  ---------
  group0            westeurope  Succeeded
  group1            westeurope  Succeeded
  group2            uksouth     Succeeded
  group3            westeurope  Succeeded
  group4            westeurope  Succeeded
  group5            westeurope  Succeeded
  group6            westeurope  Succeeded
  group7            uksouth     Succeeded
  group8            westeurope  Succeeded
  group9            westeurope  Succeeded
  </code></pre>
  
  <p>however, if I try to select just the <code>Name</code> property by doing </p>
  
  <blockquote>
    <p>az group list | select -p name</p>
  </blockquote>
  
  <p>Then i get about 2 screens full of empty lines, with nothing displayed. So the question is, what's wrong with the command above? And how should I fix it?</p>
  
  <p>I tried the following experiments to dig into the exact types of objects being returned and get some results that I don't understand. I'm hoping this will make sense to someone with more Azure and powershell experience.</p>
  
  <p>Here's the steps to reproduce the problem very easily, assuming you have an azure account. </p>
  
  <ol>
  <li>start powershell, e.g. on mac terminal, type <code>pwsh</code></li>
  <li>log in to azure <code>az login</code></li>
  <li>type <code>az group list -o table</code></li>
  </ol>
  
  <p>observe that the list comes back and is formatted correctly.</p>
  
  <ol start="4">
  <li>type <code>az group list | select -p name</code></li>
  </ol>
  
  <p>observe a few screens full of blank lines. no text.</p>
  
  <ol start="5">
  <li>scratch your head and wonder whats just happened? (grin)</li>
  </ol>
  
  <p><strong>THE PLOT THICKENS</strong></p>
  
  <p><code>az group list</code> on it's own returns a few screens full of this </p>
  
  <pre><code>[
   ... lots of these ...
   {
      "id": "/subscriptions/this-is-super-wierd-i-cant-select-name-prop/resourceGroups/spikes",
      "location": "westeurope",
      "managedBy": null,
      "name": "spikes",
      "properties": {
        "provisioningState": "Succeeded"
      },
      "tags": {},
      "type": null
    }
  ]
  </code></pre>
  
  <p>however, <code>(az group list).getType()</code> returns </p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS src&gt; (az group list).getType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     True     Object[]                                 System.Array
  </code></pre>
  
  <p>and lastly, hopefully the last 2 pieces of the puzzle</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS src&gt; (az group list)[0].getType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     True     String                                   System.Object
  </code></pre>
  
  <p>so the return types from <code>az group list</code> appear to be an <code>array of objects</code> or maybe it's an array of <code>object[]</code>, my powershell is scratchy here. So to double check, I query for the first 10 elements of that array by doing...<code>(az group list)[0..10]</code> and that returns bizarely <code>10 strings!</code>. Ok, I know it's supposed to be 10 strings, only because it's a computer and if that's what it is, then, that's what it really is. I just dont understand why.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>[
    {
      "id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/somegroup",
      "location": "westeurope",
      "managedBy": null,
      "name": "admin",
      "properties": {
        "provisioningState": "Succeeded"
      },
      "tags": {},
      "type": null
  </code></pre>
  
  <p>So all of this, to cut a long story short, is I'm wanting to know, how do you select just one property from the result of an azure query? In my case, I simply want to display the names of all my resource groups. </p>
  
  <p>This <code>az group list | select -p name</code> should work, but does not, and I'd like to know how to do it properly, and in the process find out why it didn't work, and we can all learn something about Azure and powershell in the process, and life can be great!</p>
  
  <p>Love you all,
  Alan</p>