<p>I'm attempting to utilize <a href="http://en.wikipedia.org/wiki/VBScript" rel="nofollow noreferrer">VBScript</a> to connect pull the <code>physicalDeliveryOfficeName</code> attribute in <a href="http://en.wikipedia.org/wiki/Active_Directory" rel="nofollow noreferrer">Active Directory</a> by providing the email address.  </p>

<p>I know how to do it with a common name like the following:</p>

<pre><code>Set MyUser = GetObject ("LDAP://cn=" &amp; uname &amp; ",ou=" &amp; strname &amp; ",DC=bobdom,DC=net")
</code></pre>

<p>However only the email address is available.  How to do this? I've even tried </p>

<pre><code>Set MyUser = GetObject ("LDAP://mail=" &amp; uname &amp; ",ou=" &amp; strname &amp; ",DC=bobdom,DC=net")
</code></pre>

<p>and that doesn't work.  </p>

If using an
LDAP
query (not sure if you need the server name in there in your case):
```
```
<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(objectClass=user)(mail=mike.spencer@kenblanchard.com));
```
```
Trying it out in my own environment, it looks like this (with a couple things genericized):
```
```
<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(mail=email@company.com));name,mail,member,description,memberOf,userParameters,userAccountControl,whenCreated,CN;subTreeCount=1
```
```
And the whole batch looks like this (in ASP; if done in a .vbs file you'll need to change the
```
Server.CreateObject
```
to just
```
CreateObject
```
... I think).
```
```
Set oCon        = Server.CreateObject("ADODB.Connection")
oCon.Provider   = "ADsDSOObject"
oCon.Open "ADProvider", "ADUsername", "ADPassword"

Set oCmd        = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

sQuery = "<LDAP://SERVERNAME/DC=bobdom,DC=net>;(&(mail=email@company.com));name,distinguishedName,physicalDeliveryOfficeName;subTreeCount=1>"

oCmd.CommandText = sQuery
Set ADRecordSet = oCmd.Execute
```
```
You may need to fiddle with
```
subTreeCount
```
.