Exchange 2003

Hello,

I have prepared a script which brings the result of mailbox size for all the user in exchange 2003, but I am unable to do that by using the input file for the specific users. Please help.

$Names = Import-CSV D:\MoveMailbox\Scripts\user.csv
Foreach ($Line in $Names) { 

get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size | Export-csv Mailboxsize.csv

June 24th, 2013 2:36pm

Ali,

Assuming that you are using PowerShell 3.0 and your CSV files has a 'DisplayName' column, then this should work:

$Names = Import-CSV D:\MoveMailbox\Scripts\user.csv
$displayNamesArray = $Names.DisplayName
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.MailboxDisplayName } | Export-csv Mailboxsize.csv


If you are using PowerShell 2.0 (you have to do a little extra work to build then $displayNamesArray):

$Names = Import-CSV D:\MoveMailbox\Scripts\user.csv
$displayNamesArray = @()
$Names | ForEach-Object { $displayNamesArray += $_.DisplayName }
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.MailboxDisplayName } | Export-csv Mailboxsize.csv

It's usually faster to make a single WMI call and then parse the results in memory - however, if you have a large server with lots of results and only want results on a few users, it may be better to loop through the array of users and use a WQL query to only retrieve those users.

Mike

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2013 3:17pm

Hi Mike,

I used the first script and input file I gave a heading "DisplayNAme" and next line display name of the user but the result file is coming out empty.

June 24th, 2013 4:03pm

Try this and make sure it has your display names:

$Names = Import-CSV D:\MoveMailbox\Scripts\user.csv
$displayNamesArray = $Names.DisplayName
$displayNamesArray

Once you do that, then make sure that the display name in these results matches the display names in your file:

$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Format-Table ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size

I am guessing that they do not match up (i.e. your $displayNamesArray has samAccountName or something).

Mike

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2013 4:19pm

This is how my input file look like, When I run the script it displyed the input file name on the cmdlet but the export file is empty.

DisplayName
"Huss, Ali"

$Names = Import-CSV D:\MoveMailbox\Scripts\User.csv
$displayNamesArray = $Names.DisplayName
$displayNamesArray
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.DisplayName } | Export-csv Mailboxsize.csv

June 24th, 2013 5:13pm

The fitler for Where-Object is incorrect - the property name for the $wmiResults object is $_.MailboxDisplayName, not $_.DisplayName.

$Names = Import-CSV D:\MoveMailbox\Scripts\User.csv
$displayNamesArray = $Names.DisplayName
$displayNamesArray
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.MailboxDisplayName } | Export-csv Mailboxsize.csv

You should also check the output of $wmiResults and make sure that MailboxDisplayName matches up with the names in $displayNamesArray.

Mike


Free Windows Admin Tool Kit Click here and download it now
June 24th, 2013 5:20pm

Brilliant it worked!! Thanks Mike much appreciated.
June 24th, 2013 5:29pm

Hi Mike,

One for more question, If I putting more than one user than the result file is coming out empty is there any reason why?

$Names = Import-CSV D:\MoveMailbox\Scripts\User.csv
$displayNamesArray = $Names.DisplayName
$displayNamesArray
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.MailboxDisplayName } | Export-csv Mailboxsize.csv

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2013 5:59pm

Hi Mike,

I have a slight problem with this script, In input file if I put more than one users then the export file comes out empty any reason why?

June 24th, 2013 6:09pm

Probably because you are using PowerShell 2.0.

Instead of $displayNames Array = $Names.DisplayName, use this:

$displayNamesArray = @()
$Names | ForEach-Object { $displayNamesArray += $_.DisplayName }

Mike

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2013 6:29pm

Ahh yes you are right you told me this before.. Thanks for all your help this script really helping me a lot.

June 24th, 2013 6:42pm

Hello thank you guys for this post... but in fact, what is the final script :s?
Free Windows Admin Tool Kit Click here and download it now
July 4th, 2013 5:32am

Hi,

Please see the below script this works as I wanted.

$Names = Import-CSV C:\Temp\SMTP.csv
$displayNamesArray = @()
$Names | ForEach-Object { $displayNamesArray += $_.DisplayName }
$displayNamesArray
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer Server01, Server02, Server03 | Select ServerName,StorageGroupName,StoreName,MailboxDisplayName,Size
$wmiResults | Where-Object { $displayNamesArray -contains $_.MailboxDisplayName } | Export-csv Mailboxsize.csv

July 4th, 2013 6:12am

I was about to upload it as well but the one that works for me is...

$Names = get-content "C:\Users\TricePa\Desktop\operation.txt" | Get-Mailbox
$displayNamesArray = @()
$Names | ForEach-Object { $displayNamesArray += $_.DisplayName }
$wmiResults = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer MAIL | Select MailboxDisplayName,StoreName,@{Name="Size/Mb";Expression={[math]::round(($_.Size / 1024),2)}}
$wmiResults | where-Object { $displayNamesArray -contains $_.MailboxDisplayName }

Free Windows Admin Tool Kit Click here and download it now
July 4th, 2013 6:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics