[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Exchange 2010 Powershell Scipt not working as it did on 2007

Posted on 2015-01-24
6
Medium Priority
?
335 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 1000 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

656 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