Email CollectOverMetrics.ps1 HTML Report

Exchange 2013 SP1 with 2 member DAG with 1 DB. I want to monitor the DAG using collectovermetrics.ps1. I want to have the html report from collectovermetrics.ps1 email to administrators. I know I have to have task scheduler run the command:

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -StartTime "06/15/2012" -EndTime "06/16/2012" -GenerateHTMLReport ShowHTMLReport

But how do I have that report emailed? I know you can use:

Send-MailMessage -To user@user.com -From user2@user.com -subject "This is a test" -Credential (Get-Credential)

But this fails with:

send-mailmessage : The email cannot be sent because no SMTP server was specified. You must specify an SMTP s
using either the SmtpServer parameter or the $PSEmailServer variable.
At line:1 char:1
+ send-mailmessage -to user@domian.tld -from user2@domain.tld
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.SendMailMessage

Can anyone help with this?

January 5th, 2015 2:20am

Send-MailMessage is complaining about the -SMTPServer parameter, add it and check....

-SmtpServer "FQDN of the Exchange 2013 Server"

Free Windows Admin Tool Kit Click here and download it now
January 5th, 2015 2:52am

Send-MailMessage is complaining about the -SMTPServer parameter, add it and check....

-SmtpServer "FQDN of the Exchange 2013 Server"


That worked, thank you again. So in task scheduler, the command looks something like this:

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -StartTime "06/15/2012" -EndTime "06/16/2012" -GenerateHTMLReport send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of mail server"

But I just thought of something, I need to attach that report to the email. Any ideas how to do that?
The htm that is generated is saved in the location that the script is run from and it looks like this:

Summary report is C:\Program Files\Microsoft\Exchange Server\V15\Scripts\FailoverSummary.2015_01_04_21_27_17.htm

  • Edited by forgiven Monday, January 05, 2015 3:22 AM
January 5th, 2015 3:08am

That's tricky... How frequently are you planning to run this scheduled job? If once a day then probably you can pick the HTML file using below line... That will find the html file created in last one hour in that directory, you can adjust this to number of hours in past to search...

$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

And then add "-Attachments $attachment" to Send-MailMessage cmdlet to attach that file while sending message...

So something like this...

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -StartTime "06/15/2012" -EndTime "06/16/2012" -GenerateHTMLReport 
$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name
send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of mail server" -Attachments $attachment

Make sure that you load Exchange snap-in while executing these via scheduled task, follow this for that... http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2013/Powershell/scheduling-exchange-powershell-task.html

Free Windows Admin Tool Kit Click here and download it now
January 5th, 2015 9:15pm

That's tricky... How frequently are you planning to run this scheduled job? If once a day then probably you can pick the HTML file using below line... That will find the html file created in last one hour in that directory, you can adjust this to number of hours in past to search...

$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

And then add "-Attachments $attachment" to Send-MailMessage cmdlet to attach that file while sending message...

So something like this...

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -StartTime "06/15/2012" -EndTime "06/16/2012" -GenerateHTMLReport 
$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name
send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of mail server" -Attachments $attachment

Make sure that you load Exchange snap-in while executing these via scheduled task, follow this for that... http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2013/Powershell/scheduling-exchange-powershell-task.html

I plan on running it once a day. That works from powershell. However, when I put that into task scheduler, I am unsure what the -starttime and -endtime should be or if that should even be there? Also, I assume those different parts of command should be piped together? So something like this:

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -StartTime "01/04/2015" -EndTime "01/05/2015" -GenerateHTMLReport | $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name |
send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment

The reason i assume this is because when i run it in powershell, the complete command is broken into parts. I'll try to explain:

if I copy that complete command and paste it into powershell, the first part of the command is what is run:

PS C:\Program Files\Microsoft\Exchange Server\V15\Scripts> ./CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAG1 -S
tartTime "01/04/2015" -EndTime "01/05/2015" -GenerateHTMLReport
Get statistics from exchangehost
Get statistics from exchangehost1
Found total of 2 entries
Searching for ACLL loss reports on exchangehost.
Searching for ACLL loss reports on exchangehost1.

Generated the following per-DAG reports:
C:\Program Files\Microsoft\Exchange Server\V15\Scripts\FailoverReport.DAG1.2015_01_05_20_03_55.csv

Importing data from C:\Program Files\Microsoft\Exchange Server\V15\Scripts\FailoverReport.DAG1.2015_01_05_20_03_55.csv


Generating summary report
Building summary table
Processing totals
Processing 'Mount, Automatic, Startup'
Processing 'Move, Admin, Cmdlet'
Summarising failure data
No failed operations in the data
Summary report is C:\Program Files\Microsoft\Exchange Server\V15\Scripts\FailoverSummary.2015_01_05_20_03_55.htm

PS C:\Program Files\Microsoft\Exchange Server\V15\Scripts> $attachment = "C:\Program Files\Microsoft\Exchange Server\V15
\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (ge
t-date).addhours(-1)}).name

PS C:\Program Files\Microsoft\Exchange Server\V15\Scripts> send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment

Well, it does not work when i put it into task scheduler. When running in task scheduler, the report doesnt even get generated. I tried with my added "|" and without my added "|". I clearly am not doing something right in task scheduler because it works fine when in just powershell


  • Edited by forgiven Tuesday, January 06, 2015 3:14 AM
January 6th, 2015 2:20am

You have to use ; (not |) between those lines, this says powershell that it is start of new line... 

You can use Get-Date for start and end date like below that means it will start from yesterday same time and ends right now...

-StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date)

Free Windows Admin Tool Kit Click here and download it now
January 6th, 2015 3:40am

You have to use ; (not |) between those lines, this says powershell that it is start of new line... 

You can use Get-Date for start and end date like below that means it will start from yesterday same time and ends right now...

-StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date)

Amit, you have been a big help and I want to thank you for that help. So I have this in the task scheduler arguments box:

CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment

When I run this in task scheduler, it appears as if nothing happens. Task scheduler reports it as running then goes back to ready but I never get an email. When I run the same command in powershell, now I get this error:

Generating summary report
WriteHtmlReport : Cannot bind argument to parameter 'Data' because it is null.
At C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1:1463 char:31
+         WriteHtmlReport -Data $AmOperationsData -ReportPath $HtmlSummaryReportNa ...
+                               ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [WriteHtmlReport], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,WriteHtmlReport

Summary report is C:\Program Files\Microsoft\Exchange Server\V15\Scripts\FailoverSummary.2015_01_07_15_55_18.htm
send-mailmessage : Could not find a part of the path 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\'.
At line:1 char:345
+ ./CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Send-MailMessage], DirectoryNotFoundException
    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage

And in powershell, collectovermetrics.ps1 does not run unless you add "./" to the very begginning (so it looks like this in powershell:

PS C:\Program Files\Microsoft\Exchange Server\V15\Scripts> ./CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment

January 7th, 2015 9:05pm

Looks like it doesn't have Exchange snapin added... I would suggest you to look at this to understand how to insert it...

http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2013/Powershell/scheduling-exchange-powershell-task.html

So this would be something that you would need to add in argument....

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; . 'C:\Program Files\Microsoft\Exchange Server\V15\scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment"

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 2:49am

Looks like it doesn't have Exchange snapin added... I would suggest you to look at this to understand how to insert it...

http://www.msexchange.org/kbase/ExchangeServerTips/ExchangeServer2013/Powershell/scheduling-exchange-powershell-task.html

So this would be something that you would need to add in argument....

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; . 'C:\Program Files\Microsoft\Exchange Server\V15\scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "DAG Failover Report" -smtpserver "FQDN of exchange server" -Attachments $attachment"

Yea, I meant to edit my last post and state that I copied that command from the wrong task. This is the correct command in task scheduler:

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1 -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" |  ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of email server" -Attachments $attachment"

This does not run in task scheduler but when I use the command in PS or ESM, it works fine. So it is something is not right when putting into task scheduler
  • Edited by forgiven Friday, January 09, 2015 11:17 PM
January 9th, 2015 11:09pm

I see couple of issues here...

- C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1 is not between apostrophe like this 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1'

- . is needed before that to execute it in powershell...

Because of these two task scheduler might be giving error and failing to execute the script...

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; . 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of email server" -Attachments $attachment"

Please let me know if you still get error then we can go via some old school method...

Free Windows Admin Tool Kit Click here and download it now
January 9th, 2015 11:39pm

I see couple of issues here...

- C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1 is not between apostrophe like this 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1'

- . is needed before that to execute it in powershell...

Because of these two task scheduler might be giving error and failing to execute the script...

-NonInteractive -WindowStyle Hidden -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; . 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport; $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name; send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of email server" -Attachments $attachment"

Please let me know if you still get error then we can go via some old school method...


Yea, I noticed that too and changed it to single quote '. I then ran it again and it did not work I also do not see anything in the crimson channel logging. At a loss as to why this is not running in task scheduler
January 10th, 2015 12:28am

Any ideas? Maybe some other way?
Free Windows Admin Tool Kit Click here and download it now
January 11th, 2015 10:33pm

We don't know what's going on when you run Scheduled Tasks with this cmdlet so let's separate the script and scheduled tasks.

Create a file called "C:\Scheduled Tasks\Collect Metrics.cmd" and add below content (don't add -WindowStyle Hidden which will make the window invisiable)

REM ----------------------------- Start

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command ". 'C:\Scheduled Tasks\Collect Metrics.ps1'"

REM ----------------------------- End

Now create another file called "C:\Scheduled Tasks\Collect Metrics.ps1" and add this content...

#----------------------------- Start

. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto

. 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport

$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of email server" -Attachments "$attachment"

#----------------------------- End

Now go to command prompt and go to path C:\Scheduled Tasks and run "Collect Metrics.cmd" that will show you what is going on when it is getting executed... This will help you to find what's the issue is...

Once you are able to address the issue which is coming during this run, just schedule the "C:\Scheduled Tasks\Collect Metrics.ps1" under task scheduler with the account which has proper Exchange 2013 rights and by selecting "Run weather user is logged on or not"  and "Run with highest privileges" under that task...

January 11th, 2015 11:31pm

We don't know what's going on when you run Scheduled Tasks with this cmdlet so let's separate the script and scheduled tasks.

Create a file called "C:\Scheduled Tasks\Collect Metrics.cmd" and add below content (don't add -WindowStyle Hidden which will make the window invisiable)

REM ----------------------------- Start

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command ". 'C:\Scheduled Tasks\Collect Metrics.ps1'"

REM ----------------------------- End

Now create another file called "C:\Scheduled Tasks\Collect Metrics.ps1" and add this content...

#----------------------------- Start

. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto

. 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -GenerateHTMLReport

$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN of email server" -Attachments "$attachment"

#----------------------------- End

Now go to command prompt and go to path C:\Scheduled Tasks and run "Collect Metrics.cmd" that will show you what is going on when it is getting executed... This will help you to find what's the issue is...

Once you are able to address the issue which is coming during this run, just schedule the "C:\Scheduled Tasks\Collect Metrics.ps1" under task scheduler with the account which has proper Exchange 2013 rights and by selecting "Run weather user is logged on or not"  and "Run with highest privileges" under that task...

Here is the output from the collect metrics.cmd:

C:\Scheduled Tasks>REM ----------------------------- Start

C:\Scheduled Tasks>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -No
nInteractive -command ". 'C:\Scheduled Tasks\Collect Metrics.ps1'"

         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> -?
Exchange team blog: Get-ExBlog
Show full output for a command: <command> | Format-List

Show quick reference guide: QuickRef
Tip of the day #43:

Do you have a user who has network access but maintains an external mail account outside your Exchange organization? Wit
h Exchange 2013, you can now create mail-enabled users that are regular Active Directory accounts, but also behave like
mail-enabled contacts. By using the Enable-MailUser cmdlet, you can add email contact attributes to any existing Active
Directory user who doesn't already have a mailbox on an Exchange server. Users in your Exchange organization will then b
e able to send email messages to that user's external mail account. Type:

 Enable-MailUser -Identity <Active Directory Alias> -ExternalEmailAddress <Destination SMTP Address>

VERBOSE: Connecting to FQDN.mail.server.
VERBOSE: Connected to FQDN.mail.server.
Get statistics from ACTIVE Copy DB Server
Get statistics from Passive Copy DB Server
Found total of 0 entries

Generated the following per-DAG reports:
C:\Scheduled Tasks\FailoverReport.DAGDB1.2015_01_11_22_04_57.csv

Importing data from C:\Scheduled Tasks\FailoverReport.DAGDB1.2015_01_11_22_04_57.csv

Generating summary report
WriteHtmlReport : Cannot bind argument to parameter 'Data' because it is null.
At C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1:1463 char:31
+         WriteHtmlReport -Data $AmOperationsData -ReportPath $HtmlSummaryReportNa ...
+                               ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [WriteHtmlReport], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,WriteHtmlReport

Summary report is C:\Scheduled Tasks\FailoverSummary.2015_01_11_22_04_57.htm
The property 'name' cannot be found on this object. Verify that the property exists.
At C:\Scheduled Tasks\Collect Metrics.ps1:7 char:2
+  $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

The variable '$attachment' cannot be retrieved because it has not been set.
At C:\Scheduled Tasks\Collect Metrics.ps1:9 char:164
+ ...  -Attachments "$attachment"
+                    ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (attachment:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined


C:\Scheduled Tasks>REM ----------------------------- End

C:\Scheduled Tasks>

Free Windows Admin Tool Kit Click here and download it now
January 12th, 2015 3:08am

Can you try adding below line at the top of the "Collect Metrics.cmd" file? I think it is trying to find some file under that directory but it is not able to find as it is under different directory and giving error. (you could also give this directory name under "Start in" box under Scheduled Task -> Actions when you configure it)

REM ----------------------------- Start

cd "C:\Program Files\Microsoft\Exchange Server\V15\Scripts"

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command ". 'C:\Scheduled Tasks\Collect Metrics.ps1'"

REM ----------------------------- End

January 12th, 2015 3:26am

Can you try adding below line at the top of the "Collect Metrics.cmd" file? I think it is trying to find some file under that directory but it is not able to find as it is under different directory and giving error. (you could also give this directory name under "Start in" box under Scheduled Task -> Actions when you configure it)

REM ----------------------------- Start

cd "C:\Program Files\Microsoft\Exchange Server\V15\Scripts"

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -command ". 'C:\Scheduled Tasks\Collect Metrics.ps1'"

REM ----------------------------- End


I added that to the cmd file and then ran it and received the same error as above. When I look at the failover report that is generated (the csv file), it is empty and has a size of 0kb. I have not modified the collectovermetrics.ps1 file at all
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2015 1:31pm

Any ideas?
January 12th, 2015 11:21pm

Can you try adding -ReportPath parameter in the CollectOverMetrics.ps1 line and see if it helps to organize the files in current directory?

"the ReportPath parameter is used, which causes the script to place all the files in the current directory." - http://technet.microsoft.com/en-us/library/dd351258.aspx

Free Windows Admin Tool Kit Click here and download it now
January 12th, 2015 11:37pm

Can you try adding -ReportPath parameter in the CollectOverMetrics.ps1 line and see if it helps to organize the files in current directory?

"the ReportPath parameter is used, which causes the script to place all the files in the current directory." - http://technet.microsoft.com/en-us/library/dd351258.aspx

So, here is the code with -ReportPath:

#----------------------------- Start

. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto

 . 'C:\Program Files\Microsoft\Exchange Server\V15\Scripts\CollectOverMetrics.ps1' -DatabaseAvailabilityGroup DAGDB1 -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) -ReportPath "C:\Program Files\Microsoft\Exchange Server\V15\Scripts" -GenerateHTMLReport

 $attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

 send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "this is a test" -smtpserver "FQDN" -Attachments "$attachment"

#----------------------------- End

I received the same data is null error. If you want, we can schedule a teamviewer session?
January 13th, 2015 2:32am

Any more ideas?
Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 12:55am

Hi,

I got this to work by adding another PS1 script to the Collect Metrics.cmd file named CollectOverMetricsSend.ps1:

$attachment = "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\" + (Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Scripts\*.htm" | ?{$_.lastwritetime -gt (get-date).addhours(-1)}).name

send-mailmessage -to user@domain.tld -from user2@domain.tld -subject "
this is a test" -smtpserver "FQDN" -Attachments "$attachment"

So the intial CMD file runs 2 PS1 scripts.

Cheers,

July 8th, 2015 7:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics