Solved

Exchange 2010 Powershell Scipt not working as it did on 2007

Posted on 2015-01-24
6
301 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flush end users Deleted Items via PowerShell 2 27
query all mailbox rules 5 28
List all active account in AD 2 24
exchange 2007 1 13
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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 …
In this video we show how to create a Contact 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 >> Contact ta…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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