title: Azure-PowerShell - Search-AzGraph -Query not able to join with $left or $right
body: <p>I'm looking to create a report on all policies and initiatives in my Azure tenant. To do this, I'm using Search-AzGraph in PowerShell to pull from Azure Resource Graph Explorer. I'm running into an issue when I have a query that needs joined using $left or $right. I always get a badrequest error of ParserFailure.</p>
  <p>The same query runs flawlessly in azure resource graph explorer. Need to use powershell to automate.</p>
  <p>I am running a sample query from Microsoft Azure Resource Graph Explorer:</p>
  <pre><code>   // Policy assignments and information about each of its respective definitions
  // Gets policy assignments in your environment with the respective assignment name, definition associated, category of definition (if applicable), as well as whether the definition type is an initiative or a single policy.
  // Click the &quot;Run query&quot; command above to execute the query and see results.
  policyResources
  | where type =~'Microsoft.Authorization/PolicyAssignments'
  | project policyAssignmentId = tolower(tostring(id)), policyAssignmentDisplayName = tostring(properties.displayName), policyAssignmentDefinitionId = tolower(properties.policyDefinitionId)
  | join kind=leftouter(
   policyResources
   | where type =~'Microsoft.Authorization/PolicySetDefinitions' or type =~'Microsoft.Authorization/PolicyDefinitions'
   | project definitionId = tolower(id), category = tostring(properties.metadata.category), definitionType = iff(type =~ 'Microsoft.Authorization/PolicysetDefinitions', 'initiative', 'policy')
  ) on $left.policyAssignmentDefinitionId == $right.definitionId
  </code></pre>
  <p>Error:
  <a href="https://i.stack.imgur.com/GIoRi.png" rel="nofollow noreferrer">Powershell Error</a></p>
  <p>I can remove the error by either putting a backtick prior to $left/$right or initializing the variables prior to $left = '$left'. When I do that, my join functions very strangely. The data from PolicyDefinitions is sporadic . I will sometimes get the type and category back and other times not. I would have expected the join to work or not.</p>
  <p><a href="https://i.stack.imgur.com/cCJnN.png" rel="nofollow noreferrer">CSV Output</a></p>
  <p>using the here-string:</p>
  <pre><code>    $Policies = Search-AzGraph -Query @'
      policyResources
      | where type =~'Microsoft.Authorization/PolicyAssignments'
      | project policyAssignmentId = tolower(tostring(id)), policyAssignmentDisplayName = tostring(properties.displayName), policyAssignmentDefinitionId = tolower(properties.policyDefinitionId), policyDescription = tostring(properties.description), properties.scope
      | join kind=leftouter(
       policyResources
      | where type =~'Microsoft.Authorization/PolicySetDefinitions' or type =~'Microsoft.Authorization/PolicyDefinitions'
      | project definitionId = tolower(id), category = tostring(properties.metadata.category), definitionType = iff(type =~ 'Microsoft.Authorization/PolicysetDefinitions', 'initiative', 'policy')
      ) on $left.policyAssignmentDefinitionId == $right.definitionId
  '@
  </code></pre>