string - PowerShell: Querying AD attribute "unexpected token in expression or statement -


i had change powershell script query sip address in different attribute in ad. i'm not sure how write can query "msrtcsip-primaryuseraddress" in active directory. due '-' in msrtcsip-primaryuseraddress attribute. when hover mouse on squiggly line, says "unexpected token in expression or statement"

i can query other things ad suchs name, mailnickname etc. need 1 because of way changing our sip address.

function checksip {      $loggedonuser = (get-wmiobject win32_process -filter "name='explorer.exe'"|select -first 1).getowner().user      $strfilter = "(&(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 

i'm aware of "get-aduser" command, not of our machines have commandlet natively on machine. why i'm doing this.

remember, hyphen operator. try:

[string]$sipaddress = $objitem.'msrtcsip-primaryuseraddress' 

you need specify property searcher:

$colproplist = "name", "mail", "mailnickname","msrtcsip-primaryuseraddress"; $objsearcher.propertiestoload.addrange($colproplist); 

i eliminated unnecessary loop well.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -