When it comes to querying items from Active Directory dsquery is my best friend. You need to have Active Directory Users and Computers installed to use it, but I usually run it from a Domain Controller, Exchange or Lync server anyways. Below is an example I use to query all users and grab their SIP URI, Lync pool they are homed to and the phone number. I can then take this output and paste it into Excel and format text to columns as its fixed width.
dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User))" -attr sAMAccountNAME name msRTCSIP-Line msRTCSIP-PrimaryUserAddress msRTCSIP-PrimaryHomeServer -limit 0 > C:scriptsoutputlyncinfo.txt