Solved

Exchange 2010 Powershell Scipt not working as it did on 2007

Posted on 2015-01-24
6
304 Views
Last Modified: 2015-01-24
Exchange 2010 Enterprise 64 bit
Windows 2008 R2 64 bit

Have this script that ran on Windows 2003 R2 64 bit box running exchange 2007 trying to get it to work on exchange 2010 running on Windows 2008 box

the cmd file calls a powershell script.

the cmd file is

@echo off
del c:\util\mailboxes.txt

cd\util

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command "./sendstats.ps1"

exit

The powershell script is

Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount > mailboxes.txt

get-mailboxstatistics -identity usera >>c:\util\mailboxes.txt

get-mailboxstatistics -identity userb >>c:\util\mailboxes.txt

get-mailboxstatistics -identity userc >>c:\util\mailboxes.txt

get-mailboxstatistics -identity userd >>c:\util\mailboxes.txt

get-mailboxstatistics -identity jtgrassi >>c:\util\mailboxes.txt



When I run this script it stops on Identity:

If I run the first line of the powershell script in the exchange server shell it shows this

[PS] C:\Windows\system32>Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalIt
emSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount

cmdlet Get-MailboxStatistics at command pipeline position 1
Supply values for the following parameters:
Identity:

when I run the get-mailboxstatics iidentity usera I get the correct results


It seems to me it is not passing the identity to the script as it did on windows 2003 server with exchange 2007


What am I missing here
0
Comment
Question by:Thomas Grassi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:arroryn
ID: 40568363
I'm not 100% sure about picking the bones out of your issues between Exchange 2007 and Exchange 2010, but I use the following to get a mailbox stat in 2010 which works fine.

get-mailbox * | get-mailboxstatistics | Sort totalitemsize -desc | select-object displayname, @{name="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()} }, itemcount > "C:\Program Files\Microsoft\Exchange Server\V14\Scripts\mailboxes.txt"
0
 
LVL 6

Accepted Solution

by:
arroryn earned 250 total points
ID: 40568364
Here's a batch file and full script, which you can then use to schedule sending. Again, works in Exchange 2010.

Batch File:

del "C:\Program Files\Microsoft\Exchange Server\V14\Scripts\mailboxes.txt" /q
PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command ". 'C:\Program Files\Microsoft\Exchange Server\V14\Scripts\SendStats.ps1'"

###Send mailbox statistics script

###First, the administrator must change the mail message values in this section 
$FromAddress = "sending@sender.com"
$ToAddress = "recipient@recipient.com" 
$MessageSubject = "Mailbox Size Report" 
$MessageBody = "Message Body Here" 
$SendingServer = "exchangeserver.domain.local" 


###Now get the stats and store in a text file 
get-mailbox * | get-mailboxstatistics | Sort totalitemsize -desc | select-object displayname, @{name="Size (MB)";expression={$_.TotalItemSize.Value.ToMB()} }, itemcount > "C:\Program Files\Microsoft\Exchange Server\V14\Scripts\mailboxes.txt"


###Create the mail message and add the statistics text file as an attachment 
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, 
$MessageSubject, $MessageBody 
$Attachment = New-Object Net.Mail.Attachment("C:\Program Files\Microsoft\Exchange Server\V14\Scripts\mailboxes.txt") 
$SMTPMessage.Attachments.Add($Attachment) 

###Send the message 
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer 
$SMTPClient.Send($SMTPMessage) 

Open in new window

0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40568422
Get-MailboxStatistics

If you read the details of this powershell command "identity" is required and is the first positional parameter. So you HAVE to specific this value. As it has already been said you can use Get-Mailbox | Get-MailboxStatistics..... and this will work.

You can also add users to a txt or csv file and call it from a variable like below...

$users = get-content "c:\name.txt"
foreach ($user in $users) {
Get-MailboxStatistics -Identity $user | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalIt
 emSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount
}

Open in new window


Will.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40568430
Guys

Got it working now

One last question

When I do and individual get-mailboxstatics  I get StoragelimitSttaus and lastlogontime

where can I add that in the above?
0
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 250 total points
ID: 40568446
Just add these attributes after ft (fotmat table) in the command. See below...

Get-mailbox | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,StoragelimitSttaus, lastlogontime@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount > mailboxes.txt

Open in new window


Will.
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 40568536
Thanks guys it is now working.

I have another question open if you guys want to take a look at

http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_28603184.html


Thanks
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
This video discusses moving either the default database or any database to a new volume.

739 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