title: PowerShell: Querying AD attribute "unexpected token in expression or statement
body: <p>I recently had to change my powershell script to query a SIP address in a different attribute in AD.  But I'm not sure how to write it so I can query the "msRTCSIP-PrimaryUserAddress" in Active Directory.  This is due to the '-' in the msRTCSIP-PrimaryUserAddress attribute.  When I hover my mouse over the squiggly line, it says "unexpected token in expression or statement"</p>
  
  <p>I can query other things from AD suchs as name, mailnickname etc.   But I need this one specifically because of the way we are changing our SIP address.</p>
  
  <pre><code>Function CheckSIP {
  
      $loggedOnUser = (get-WmiObject win32_process -Filter "Name='explorer.exe'"|Select -First 1).GetOwner().User
  
      $strFilter = "(&amp;(objectCategory=User)(mailnickname=$loggedOnUser))"
      $objDomain = New-Object 
  
      System.DirectoryServices.DirectoryEntry("LDAP://OU=Offices,dc=OurNetwork,dc=net")
      $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
      $objSearcher.SearchRoot = $objDomain
      $objSearcher.PageSize = 1000
      $objSearcher.Filter = $strFilter
      $objSearcher.SearchScope = "Subtree"
  
      $colProplist = "name", "mail", "mailnickname", "msRTCSIP-PrimaryUserAddress"
      foreach ($i in $colPropList){$null = $objSearcher.PropertiesToLoad.Add($i)}
  
      $colResults = $objSearcher.FindAll()
  
      foreach ($objResult in $colResults){
  
          $objItem = $objResult.Properties
          [string]$UserName = $objItem.name 
          [string]$mail = $objItem.mail
          [string]$mailnickname = $objItem.mailnickname
          [string]$sipaddress = $objItem.msRTCSIP-PrimaryUserAddress
      }
  
      $theSIP = $sipaddress.Split("@")[0]    
      return $theSIP
  }
  
  $mySIPaddress = CheckSip
  </code></pre>
  
  <p>I'm aware of the "Get-ADUser" command, but not all of our machines will have this commandlet natively on their machine.  So that is why I'm doing it like this.</p>