Solved

Powershell script to display Exchange 2003 Mailboxes by Location

Posted on 2010-08-17
5
646 Views
Last Modified: 2012-05-10
I am currently running the following script to display the number of mailboxes that exist in the Exchange 2003 environment:
$servers='server01'#, 'server02'
$outfile="c:\scripts\serverbylocation.csv"
 Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $servers `
| select-object MailboxDisplayName,Size,ServerName,StorageGroupName,StoreName `
| export-csv $outfile -notype

What do I need to do to add in the AD object of  physicaldeliveryofficename?
What I would like to do is have the option to sort my results by location.
0
Comment
Question by:jahhan
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:Jamie_Wilson
ID: 33457948
Can you just not add physicaldeliveryofficename to your current script ?

e.g.
$servers='server01'#, 'server02'
$outfile="c:\scripts\serverbylocation.csv"
 Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $servers `
| select-object MailboxDisplayName,Size,ServerName,StorageGroupName,StoreName,physicaldeliveryofficename `
| export-csv $outfile -notype
0
 

Author Comment

by:jahhan
ID: 33458102
I tried that but when I execute the script that column is blank.
0
 
LVL 4

Expert Comment

by:Jamie_Wilson
ID: 33458254
Do you get the same thing if physicaldeliveryofficename is the 1st object?
0
 

Author Comment

by:jahhan
ID: 33458412
Yes and the same outcome.
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 33462375

WMI doesn't return that field. You have to pull it from AD.

No means to test this, should be this or very close to this.

Chris
$servers='server01'#, 'server02'

$outfile="c:\scripts\serverbylocation.csv"

Get-WmiObject Exchange_Mailbox -Namespace root\MicrosoftExchangeV2 -computer $servers | 
  Select-Object MailboxDisplayName, Size, ServerName, StorageGroupName, StoreName, `
    @{n='Office';e={ 
      $User = (New-Object DirectoryServices.DirectorySearcher("(legacyExchangeDN=$($_.LegacyDN))")).FindOne()
      $User.Properties["physicaldeliveryofficename"][0] }} | 
  Export-Csv $outfile -NoTypeInformation

Open in new window

0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question