title: How to compare two custom ps custom objects and change the value of one based on the result of another?
body: <p>Currently I have two sql queries that I have outputting the following columns</p>
  
  <pre><code>$A | Select-Object -Property DatabaseUserName, Role, PermissionType, PermissionState, ObjectType, ObjectName, col
  </code></pre>
  
  <p>AND </p>
  
  <pre><code>$B | Select-Object -Property DatabaseUserName, sysadmin
  </code></pre>
  
  <p>What I want to do in psuedo code: WHERE $B.DatabaseUserName = $A.DatabaseUserName THEN $A.col = $B.sysadmin. Currently I have it setup the following way:</p>
  
  <pre><code>$allUsers = $A | % {
          New-Object psobject -Property @{
              DatabaseUserName = $_.DatabaseUserName
              Role = $_.Role
              PermissionType = $_.PermissionType
              PermissionState = $_.PermissionState
              ObjectType = $_.ObjectType
              ObjectName = $_.ObjectName
              col = 0
          }
      }
  
      $allUsers += $B | Where-Object {$_.DatabaseUserName -like $B.DatabaseUserName} | % {
          New-Object psobject -Property @{
              $_.col = $B.sysadmin
  
          }
      }
  </code></pre>
  
  <p>This still leaves all the columns to be 0 from what I can see when I want them to actually be the value of $B.sysadmin. I am not sure if this is the correct approach.</p>