title: How to output hash table query result into Out-GridView?
body: <p>I wish to export a hashtable result into Out-GridView using the Powershell.</p>
  <p>The purpose of the below script is to export the <strong>Azure VM tags to Out-GridView</strong>, it throws error like the below blank result:</p>
  <p><a href="https://i.stack.imgur.com/iJU9O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iJU9O.png" alt="enter image description here" /></a></p>
  <p>Error on the console:</p>
  <pre><code>Out-GridView : Syntax error in PropertyPath 'Syntax error in Binding.Path '[ Product] ' ... '(Tag)'.'.
  At line:46 char:19
  +         $Output | Out-GridView #Export-Csv -Path c:\temp\1a.csv -appe ...
  +                   ~~~~~~~~~~~~
      + CategoryInfo          : OperationStopped: (:) [Out-GridView], InvalidOperationException
      + FullyQualifiedErrorId : ManagementListInvocationException,Microsoft.PowerShell.Commands.OutGridViewCommand
  </code></pre>
  <p>This is the actual script which was executed under the Global Administrator role:</p>
  <pre><code>&lt;#
  .AUTHOR: https://stackoverflow.com/users/13390556/lukasz-g
  #&gt;
  $Subscription = Get-AzSubscription | Out-GridView -Title 'Select subscription' -OutputMode 'Multiple'
  
  # Initialise output array
  $Output = @()
  
  if ($Subscription) {
      foreach ($item in $Subscription) {
          $item | Select-AzSubscription
  
          # Collect all the resources or resource groups (comment one of below)
          $Resource = Get-AzResource
          #$Resource = Get-AzResourceGroup
  
          # Obtain a unique list of tags for these groups collectively
          $UniqueTags = $Resource.Tags.GetEnumerator().Keys | Get-Unique -AsString | Sort-Object | Select-Object -Unique | Where-Object { $_ -notlike &quot;hidden-*&quot; }
  
          # Loop through the resource groups
          foreach ($ResourceGroup in $Resource) {
              # Create a new ordered hashtable and add the normal properties first.
              $RGHashtable = New-Object System.Collections.Specialized.OrderedDictionary
              $RGHashtable.Add(&quot;Name&quot;, $ResourceGroup.ResourceGroupName)
              $RGHashtable.Add(&quot;Location&quot;, $ResourceGroup.Location)
              $RGHashtable.Add(&quot;Id&quot;, $ResourceGroup.ResourceId)
              $RGHashtable.Add(&quot;ResourceType&quot;, $ResourceGroup.ResourceType)
  
              # Loop through possible tags adding the property if there is one, adding it with a hyphen as it's value if it doesn't.
              if ($ResourceGroup.Tags.Count -ne 0) {
                  $UniqueTags | Foreach-Object {
                      if ($ResourceGroup.Tags[$_]) {
                          $RGHashtable.Add(&quot;[$_] (Tag)&quot;, $ResourceGroup.Tags[$_])
                      }
                      else {
                          $RGHashtable.Add(&quot;[$_] (Tag)&quot;, &quot;-&quot;)
                      }
                  }
              }
              else {
                  $UniqueTags | Foreach-Object { $RGHashtable.Add(&quot;[$_] (Tag)&quot;, &quot;-&quot;) }
              }
  
              # Update the output array, adding the ordered hashtable we have created for the ResourceGroup details.
              $Output += New-Object psobject -Property $RGHashtable
          }
  
          # Sent the final output to CSV
          $Output | Out-GridView #Export-Csv -Path c:\temp\1a.csv -append -NoClobber -NoTypeInformation -Encoding UTF8 -Force
      }
  }
  </code></pre>