Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get-wmiobject legacydn - how do I get distinguishedname?

Status
Not open for further replies.

kokser

Programmer
Sep 25, 2009
90
DK
Title may be a little misleading.

Currently I have a small simple script that just outputs some information of users mailbox'.

Code:
$filecsv = "test.csv"
$date = get-date -uformat %Y/%m/%d
get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName koks-u549ckztx1 | select-object @{name="Username";expression={$_.MailboxDisplayName}}, Size, TotalItems, LegacyDN, @{name="Dato";expression={$date}}
But I am not very happy about the legacydn value. As I am on a SBS 2003 with Exchange 2003, there is no pssnapin to load, so this makes getting each users DN a bit harder than I had hoped (I think?).

Any ideas how to get the DN for the user for each mailbox?
 
As you discovered, LegacyDN is actually an Exchange attribute and not the AD Distinguished Name for the account. The only thing I found was a post using the Quest AD cmdlets like this
Code:
Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer server1 | select MailboxDisplayName, Size, TotalItems, LegacyDN, @{Name="DN"; Expression={ (Get-QADUser $_.LegacyDN).DN}}

based on a post by Shay Levy in the forums at Powergui.org,
I see a few options:
* Install the Quest AD cmdlets on your SBS box and use the above code
* Write a function that uses the native PowerShell/.NET ADSI abilities to get a DN based on LegacyDN, and call it similar to the code above (replacing Get-QADUser)
* Write that same function, collect your mailbox info in a variable, then loop through the mailboxes in the variable and call the function to retrieve the DN
 
ah, indeed that works! I already installed quesst after starting this thread, but failed to find exactly what you did. This is perfect :)

Thank you very much for your help!

Oh, is there a way to exclude system mailboxes?
 
It might be possible using the -query or -filter parameters on Get-WMIObject, but I haven't found the right syntax. It would be faster that way. If nothing else however, you could use a Where-Object selection:
Code:
Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer server1 | Where {($_.MailboxDisplayName -notmatch "SystemMailbox") -and ($_.MailboxDisplayName -notmatch "SMTP")} | Sort MailboxDisplayName | Select MailboxDisplayName, Size, TotalItems, LegacyDN, @{Name="DN"; Expression={ (Get-QADUser $_.LegacyDN).DN}}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top