Solved

GetMailboxStatistics task scheduler

Posted on 2014-10-21
12
214 Views
Last Modified: 2014-10-21
I would like to get this added to a task schedule but my command is wrong I guess as it just says it is running but doesn't actually do anything. I would like to get this report emailed to me rather than dumped to the hard drive if it is possible?

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'; Connect-ExchangeServer –auto; "Get-Mailbox | Select-Object Displayname,Database,@{Name='TotalItemSize'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).TotalItemSize))}},@{Name='ItemCount'; Expression={[String]::join(";",((Get-MailboxStatistics -identity $_.identity).ItemCount))}},IssueWarningQuota, ProhibitSendQuota | export-csv -path "c:\mailboxsizes.csv"
0
Comment
Question by:stlhost
  • 6
  • 4
  • 2
12 Comments
 
LVL 34

Expert Comment

by:Seth Simmons
ID: 40394997
1) are the exchange extensions being loaded?
2) is the task running with highest privileges?
3) does it work when you run it manually?
4) you can pipe the output to Send-MailMessage (if you have powershell 4 installed)

Send-MailMessage
http://technet.microsoft.com/en-us/library/hh849925.aspx
0
 
LVL 2

Author Comment

by:stlhost
ID: 40395016
1) yes
2) No, forgot about that.
3) Well now that you ask, no. All I get is ,,,,,, If I run the command without C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'; Connect-ExchangeServer –auto; it does work.
4) [PS] C:\Windows\system32>$PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
0
 
LVL 34

Expert Comment

by:Seth Simmons
ID: 40395035
what version of windows and exchange?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40395037
That commands are too many to keep them properly entered on a single line. And because of that, there are unmatched and errornous quotes, and other stuff.

First off all, you provide -noexit - of course PS will not exit then after executing the command, keeping the scheduled task running forever without doing anything. That needs to get removed. And for the remainder I strongly encourage to use a PS1 file consisting of:
. 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'
Connect-ExchangeServer –auto
Get-Mailbox | % {
  $stats = Get-MailboxStatistics -identity $_.identity
  $_ | Select-Object Displayname, Database,
    @{Name='TotalItemSize'; Expression={[String]::join(";", $stats.TotalItemSize)}},
    @{Name='ItemCount'; Expression={[String]::join(";",$stats.ItemCount)}},
    IssueWarningQuota, ProhibitSendQuota
} | set-variable Result
Send-MailMessage -SmtpServer mx.There.com -From Me@Here.com -To You@There.com -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join "`n")

Open in new window

BTW, it is not true you can just pipe content to Send-MailMessage - pipe input is treated as attachment file names, not body text. That didn't change (officially) for PS4.
0
 
LVL 2

Author Comment

by:stlhost
ID: 40395046
Windows 2008 R2


AdminDisplayVersion                     ExchangeVersion
-------------------                     ---------------
Version 14.1 (Build 218.15)             0.1 (8.0.535.0)
0
 
LVL 2

Author Comment

by:stlhost
ID: 40395076
Qlemo

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 68

Expert Comment

by:Qlemo
ID: 40395096
Probably a restriction with the Remote Exchange shell. Let's remove the optimizations, and just run your corrected script:
. 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'
Connect-ExchangeServer –auto
Get-Mailbox | Select-Object Displayname, Database,
    @{Name='TotalItemSize'; Expression={[String]::join(";", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},
    @{Name='ItemCount'; Expression={[String]::join(";",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},
    IssueWarningQuota, ProhibitSendQuota
} | set-variable Result
Send-MailMessage -SmtpServer mx.There.com -From Me@Here.com -To You@There.com -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join "`n")

Open in new window

0
 
LVL 2

Author Comment

by:stlhost
ID: 40395264
Unexpected token '}' in expression or statement.
At C:\mailboxstats.ps1:7 char:2
+ } <<<<  | set-variable Result
    + CategoryInfo          : ParserError: (}:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40395303
Sorry for that, left something over:
. 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'
Connect-ExchangeServer –auto
Get-Mailbox | Select-Object Displayname, Database,
    @{Name='TotalItemSize'; Expression={[String]::join(";", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},
    @{Name='ItemCount'; Expression={[String]::join(";",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},
    IssueWarningQuota, ProhibitSendQuota |
  set-variable Result
Send-MailMessage -SmtpServer mx.There.com -From Me@Here.com -To You@There.com -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join "`n")

Open in new window

0
 
LVL 2

Author Comment

by:stlhost
ID: 40395334
Update-TypeData : The following error occurred while loading the extended type data file:
Microsoft.PowerShell, E:\Exchange Binaries\bin\exchange.types.ps1xml : File skipped because it was already present from
 "Microsoft.PowerShell".
At E:\Exchange Binaries\Bin\RemoteExchange.ps1:94 char:17
+     Update-TypeData <<<<  -PrependPath $typeFilePath
    + CategoryInfo          : InvalidOperation: (:) [Update-TypeData], RuntimeException
    + FullyQualifiedErrorId : TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand

Update-TypeData : The following error occurred while loading the extended type data file:
Microsoft.PowerShell, E:\Exchange Binaries\bin\Exchange.partial.Types.ps1xml : File skipped because it was already pres
ent from "Microsoft.PowerShell".
Microsoft.PowerShell, E:\Exchange Binaries\bin\exchange.types.ps1xml : File skipped because it was already present from
 "Microsoft.PowerShell".
At E:\Exchange Binaries\Bin\RemoteExchange.ps1:104 char:16
+ Update-TypeData <<<<  -PrependPath $partialTypeFile
    + CategoryInfo          : InvalidOperation: (:) [Update-TypeData], RuntimeException
    + FullyQualifiedErrorId : TypesXmlUpdateException,Microsoft.PowerShell.Commands.UpdateTypeDataCommand


         Welcome to the Exchange Management Shell!

Full list of cmdlets: Get-Command
Only Exchange cmdlets: Get-ExCommand
Cmdlets that match a specific string: Help *<string>*
Get general help: Help
Get help for a cmdlet: Help <cmdlet name> or <cmdlet name> -?
Show quick reference guide: QuickRef
Exchange team blog: Get-ExBlog
Show full output for a command: <command> | Format-List

Tip of the day #67:

Want to customize your Exchange Management Shell profile? Run the following command to determine the location of your Mi
crosoft.PowerShell_profile.ps1 file:

 $Profile

You may have to create the PSConfiguration folder and Microsoft.PowerShell_profile.ps1 file. After you've done that, you
 can add your favorite functions and aliases, which will be loaded every time that the Exchange Management Shell is open
ed.

VERBOSE: Connecting to CTEXCH02.xxx.local
VERBOSE: Connected to CTEXCH02.xxx.local.
[PS] C:\>

Open in new window

0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40395357
That is because you run the script or code more than once in the same PS session. It is trying to do the necessary imports and connect to Exchange again, but the imports may only happen once. You should be able to just ignore that, the script should continue. In your scheduled task this will not happen, as PS is started newly each time.
0
 
LVL 2

Author Comment

by:stlhost
ID: 40395391
I figured as much. Thanks so much
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
In this video we show how to create a mailbox database 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 Servers >> Data…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

757 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

22 Experts available now in Live!

Get 1:1 Help Now