• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Exchange 2010 Powershell Scipt not working as it did on 2007

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
Thomas Grassi
Asked:
Thomas Grassi
  • 2
  • 2
  • 2
2 Solutions
 
arrorynCommented:
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
 
arrorynCommented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Thomas GrassiSystems AdministratorAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
Thomas GrassiSystems AdministratorAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now