Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetMailboxStatistics task scheduler

Posted on 2014-10-21
12
Medium Priority
?
238 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
[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
  • 6
  • 4
  • 2
12 Comments
 
LVL 35

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 35

Expert Comment

by:Seth Simmons
ID: 40395035
what version of windows and exchange?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 71

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
 
LVL 71

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 71

Accepted Solution

by:
Qlemo earned 2000 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 71

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
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…
Suggested Courses

715 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