title: Passing string in Get-ADUser filter parameter causes error - property not found in pscustomobject
body: <p>I'm trying to create a new Active Directory user, but first I verify that the user doesn't exist already with <code>Get-ADUser</code>.
  I import the user data from our HR department and build custom properties:</p>
  
  <pre><code>$newUsers = Import-Csv $csvFile |
              Select-Object -Property @{n='EmpNum';e={$_.'Employee Number'}},
                  @{n='UPN';e={$_.'Email Address'}},
                  @{n='Alias';e={$_.'Email Address'.Split("@")[0]}} #### etc
  </code></pre>
  
  <p>When I loop through the objects from the CSV file, I use the UPN property to search for the user in Active Directory:</p>
  
  <pre><code>foreach ($newUser in $newUsers) {
      $exists = Get-ADUser -Filter {UserPrincipalName -eq $newUser.UPN} -Properties * -Server $adServer -Credential $adCred 
      ...
  }
  </code></pre>
  
  <p>The filter causes an error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Get-ADUser : Property: 'UPN' not found in object of type:
  'System.Management.Automation.PSCustomObject'. At
  C:\Users\bphillips.NEWHOPEOFIN\Dropbox\Powershell\NewHire\AddNewDSP.ps1:50
  char:15
  +     $exists = Get-ADUser -Filter {UserPrincipalName -eq $newUser.UPN} -Propertie ...
  </code></pre>
  
  <p>I've tried doing this: -Filter {UserPrincipalName -eq $("$newUser.UPN") but that doesn't help; I get another error</p>
  
  <pre class="lang-none prettyprint-override"><code>Get-ADUser : Cannot process argument because the value of argument
  "path" is not valid. Change the value of the "path" argument and run
  the operation again. At
  C:\Users\bphillips.NEWHOPEOFIN\Dropbox\Powershell\NewHire\AddNewDSP.ps1:50
  char:15
  +     $exists = Get-ADUser -Filter {UserPrincipalName -eq $("$newUser.UPN")} -Prop ...
  </code></pre>
  
  <p><code>$newUser</code> is a string, so I don't understand why it causes a problem. Hard-coding a UserPrincipalName like, "test@ourcompany.com" works, but the <code>$newUser.UPN</code> won't work.**</p>
  
  <pre class="lang-none prettyprint-override"><code>PS C:\&gt; $newUser.UPN.GetType()
  
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     True     String                                   System.Object
  </code></pre>
  
  <p>and </p>
  
  <pre class="lang-none prettyprint-override"><code>PS C:\&gt; $newUser.UPN | gm
  
     TypeName: System.String
  </code></pre>
  
  <p><code>$newUser.UPN</code> contains a valid string value</p>
  
  <pre class="lang-none prettyprint-override"><code>PS C:\&gt; $newUser.UPN
  ypope@ourcompany.net
  </code></pre>
  
  <p>What do I have to do to get <code>$newUser.UPN</code> to be recognized as a string for the filter parameter? What's going on that I don't understand?</p>