Solved

Exchange 2010 Powershell Scipt not working as it did on 2007

Posted on 2015-01-24
6
275 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:arroryn
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 23

Author Comment

by:Thomas Grassi
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now