views:

726

answers:

1

I'm using powershell to pull a list of exchange 2003 users and based on the user's mailbox "LegacyDN", I was hoping to use an LDAP query to pull their activesyncenabled property (msExchOmaAdminWirelessEnable), description, and office; however, it doesn't seem to be coming up for me. any ideas?

here is how i'm querying for the AD attributes:

$allusers = get-wmiobject -class exchange_mailbox -namespace root\microsoftexchangev2 -computername srv02 | select mailboxdisplayname, legacyDN 

foreach ($user in $allusers) 
{
$obj = new-object psobject 
$exchangever = "2003" 

$tmp = [adsi]("LDAP://" + $user.legacydn) 

$obj | add-member -membertype noteproperty -name "Display Name" -value $user.mailboxdisplayname
$obj | add-member -membertype noteproperty -name "Office" -value $tmp.physicaldeliveryofficename 
$obj | add-member -membertype noteproperty -name "Description" -value $tmp.description 
$obj | add-member -membertype noteproperty -name "Activesync" -value $tmp.msExchOmaAdminWirelessEnable 

$allusersemail += $obj 

}

$alluseremail | export-csv \\srv02\logs\test.csv
A: 

Here's one way:

$search = System.DirectoryServices.DirectorySearcher

$search.filter = "(&(homeMDB=*)(objectcategory=user)(objectclass=user))"

$props = "mailNickName","displayName","physicaldeliveryofficename","description","msExchOmaAdminWirelessEnable"

$props | foreach { [void]$search.PropertiesToLoad.Add($_) }

$users = $search.findAll()

foreach($u in $users)

{

$DisplayName = @{name="DisplayName";expression={$u.properties.item("DisplayName")}}

$Office = @{name="Office";expression={$u.properties.item("physicaldeliveryofficename")}}

$Description = @{name="Description";expression={$u.properties.item("Description")}}

$Activesync = @{name="Activesync";expression={$u.properties.item("msExchOmaAdminWirelessEnable")}}

$u | select $DisplayName,$Office,$Description,$Activesync

}

Shay Levy
is there a way to do this if you are just given a mailbox guid?
phill
I'm not sure how to filter AD using mailboxGuid.
Shay Levy