Solved

Help to build a PowerShell Script

Posted on 2014-01-23
38
643 Views
Last Modified: 2014-02-02
Hello Experts,

I would like to include all power shell cmdlets below into a single master script, and run from any server, therefore, I have to include the power shell AD and Exchange modules plus all the commands below. I would like to save all the results[txt files] to a shared folder, and displayed the information for each test on a HTML page, as well to send an email to a specific email mailbox

1. Get-DatabaseAvailabilityGroup -Status | fl >c:\dag.txt
2. Get-DatabaseAvailabilityGroupNetwork | fl >c:\dagNetwork.txt
3. Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | fl > c:\MdbCopy.txt
4. Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus >c:\mdbcopy2.txt
5. Get-MailboxDatabase -Status | fl >c:\mdb.txt
6. Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | fl >c:\rphealth.txt
7. Get-ExchangeServer -Status | fl >c:\srv.txt
8. Get-MailboxServer -Status | fl >c:\mbsrv.txt
9. Get-DomainController >c:\dc.txt


Any ideas?
0
Comment
Question by:Jerry Seinfield
[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
  • 18
  • 14
  • 3
38 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 39803487
I think one of the core ingredients you're missing is to store the output into variables first.  Then you can work with that data appropriately to build an HTML output page, do your separate outputs to your log files, and then email the results.

$OverallVariable = @()
$Variable = <command>
$OverallVariable+= $Variable

$HTML = "<HTML>`n `
<HEAD>`n `
<TITLE>Test Title</TITLE>`n `
</HEAD>`n `
<BODY>`n `
This is my first HTML Variable output<br>`n `
$DatabaseAvailabilityGroupOutput `n `
<p>`n `
This is my second variable output<br> `n `
$DatabaseAvailabilityGroupNetworkOutput `n `
</BODY>`n `
</HTML>"
$HTML > "OutputHTMLFile.htm"

Things to note: `n = new line which will make your HTML file easier to read when it's output into the htm file, but as you know, spacing doesn't matter for HTML.  Also ` at the end of each line (backtick is the name of the symbol, next to the 1 key) signifies to Powershell that you're doing a continuation of the line, so essentially it's all one big line.  This is done to allow you to easily edit your powershell script output so you're not having to deal with a huge long line of code.

Hope that gets you started in the right direction, but like I mentioned, if you can get one to do all of those things (googling each separate thing you want to do like send an email is very doable), you can get them all.  It will turn into a pretty lengthy script.  I made a script in the past where I was doing the exact same thing, and it would have 5 or 6 functions, all based on health and availability, and then I would use that to test different left and right limits of acceptable operation and have it tell me when it needed to be looked at.  So I would get an email with "Green" or "Red" status of each service I was testing.  Getting the output into emails is one thing, but testing the output for what signifies work to be done on your part as the administrator is the thing that Powershell could really help with.  For example, if the backup wasn't done daily, our logs would be >24 hours old, I could test for that and it would send me an email saying to backup the mailstore since it wasn't done.  Also, I would go through each server and get the hard drive space percentages.  Based on that data, I wanted an email that rolled up the servers that had less than 30% space remaining, I didn't want to see which servers were above that level.

-Dale Harris
0
 

Author Comment

by:Jerry Seinfield
ID: 39803541
Hi Dale,

What if we remove the HTML request from the equation and just build the script with the commands above, and save all results onto a shared folder, and in one line send an email to a mailbox with all results above?

if so, how would the script looks?
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 39803584
Here's an example of your first command, just rinse and repeat for each:

$FilePath = "\\10.10.10.10\sharedfolder"
$FileName = "LogFile.txt"
$Body = @()
$GDAG = Get-DatabaseAvailabilityGroup -Status | fl
$GDAG >> "$FilePath\$FileName"

$Body += $GDAG
send-mailmessage -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -subject "Test mail" -body $Body -smtpserver "Exchange.contoso.com"
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

Author Comment

by:Jerry Seinfield
ID: 39803601
Should I repeat all code above for each PowerShell cmdlets? Basically what I need is

1. Run all powershell cmdlets above, save all results[each txt file] onto a shared folder
2. Send a single email with all the results[files above] to a specific email address
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39804021
That depends on whether you want to have individual emails for each report. If not, I recommend to convert the output of each command to a HTML Table (fragment), concat those together,  put some HTML code around and in between. The result can be used in a HTML page and as email.

Whatever you do, I recommend to write a function doing the work, so you can use something like:
Get-DatabaseAvailabilityGroup -Status | Set-Report '\\server\share\dag.txt'

Open in new window

if sending one mail per result, or
$body = Get-DatabaseAvailabilityGroup -Status | Set-Report '\\server\share\dag.txt'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report '\\server\share\dagNetwork.txt'
# ...
Send-MailMessage <# etc #>

Open in new window

with your self-created function for the latter
function Set-Report (
  [parameter (ValueFormPipeline=$true)} $obj,
  [parameter (Position=0)] $file
)
{
  $obj |  fl * > $file
  $obj | convertToHtml -Fragment
}

Open in new window

The Set-Report can do additional formatting, sending the mail, or whatever you like.
0
 

Author Comment

by:Jerry Seinfield
ID: 39804949
Thanks Qlemo,

Can you please combine all code above, and send me the final script?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39805128
Ok. I'll use  the "single HTML mail" approach. You can add more HTML formatting if needed, and change the titles to something more appealing.
function Set-Report (
  [parameter (ValueFormPipeline=$true)} $obj,
  [parameter (Position=0)] $file
  [parameter (Position=1)] $title
)
{
  $obj |  fl * > $file
  "<h2>$title</h2>"
  $obj | convertToHtml -Fragment -Title $title
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39805249
you rock

Thanks

I have one more question, and please let me know if another ticket is requested as the original ticket is resolved.

I am thinking of creating an automatic task on my domain controller or create a runbook on the orchestrator server to call the script above, but if I want to avoid duplication of the files obtained above,


Any chance to get those files with a format yyyy/dd/mm.txt? where yyyy/dd/mm is the actual date when the script is executed

For example

Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag20142301.txt

Please advice
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39805282
The best, but more complex, approach is to add the date in Set-Report itself.
The simple one is to add it to the call of Set-Report, as in your example above.
I'll show the complex one.
function Set-Report (
  [parameter (ValueFormPipeline=$true)} $obj,
  [parameter (Position=0)] $file
  [parameter (Position=1)] $title
)
{
  $file = (split-path -Paren
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertToHtml -Fragment -Title $title
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

Note that the files will be   xyz.yyyymmdd.txt  - you should always use a sortable date format, and yyyyddmm isn't, as "20142302" is "earlier" than "20142401", which certainly is not intented.
0
 

Author Comment

by:Jerry Seinfield
ID: 39805352
Thanks QLemo

As this script will run in a member server

Should we import the modules for AD and Exchange?  Can you please add the lines before the function?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39806932
This should be all you need. Put it to the very top of the script.
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
import-module ActiveDirectory

Open in new window

0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 39807021
That script looks great, Qlemo.  I just noticed a slight hiccup on your 2nd line:
[parameter (ValueFormPipeline=$true)} $obj,

I think Value*From*PipeLine will need to be used.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39807260
That's absolutely correct. And there was a wrong line 7. So:
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
import-module ActiveDirectory

function Set-Report (
  [parameter (ValueFromPipeline=$true)} $obj,
  [parameter (Position=0)] $file
  [parameter (Position=1)] $title
)
{
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertToHtml -Fragment -Title $title
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39807272
Thanks You Folks for the help
0
 

Author Comment

by:Jerry Seinfield
ID: 39807437
Folks, I know that i just close this ticket, but I was unable to run the powershell script above either by running the script or manually from powershell console and /or Exchange management shell

Please see attached screen shoots

Any ideas?

I tried to run from a domain controller, from an exchange servers, still no luck
ErrorUnabletoSetReport.png
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39808630
Still some typos - but you should have seen the important error messages at the top.
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
import-module ActiveDirectory

function Set-Report (
  [parameter (ValueFromPipeline=$true)] $obj,
  [parameter (Position=0)] $file,
  [parameter (Position=1)] $title
)
{
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertToHtml -Fragment -Title $title
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39808971
Hi Qlemo,

still no luck, please see errors from screen shoots
ErrorFromMSExchangeServer.jpg
ErrorFromPowershellinDomainContr.jpg
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39809009
My keyboard seems to suck up keys. convertToHtml is missing a dash, and should sound convertTo-Html. And there should be no space after Parameter ...
I don't know what to do with the second screenshot - it tells the Exchange cmdlets were not found, though they are in the first one.
add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
import-module ActiveDirectory

function Set-Report (
  [parameter(ValueFromPipeline=$true)] $obj,
  [parameter(Position=0)] $file,
  [parameter(Position=1)] $title
)
{
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertTo-Html -Fragment -Title $title
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39809146
still no luck, I ran manually the script from windows power shell console on both domain controller and exchange mailbox server with no luck, please see new attached files[error 4 and 5]

Even if I run the script from exchange management shell, got same errors

Just to clarify, our DCs are Wndows 2008 R2, same OS for exchange 2010 SP3 servers
Error4.jpg
Error5.jpg
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39809417
Firstly, you won't just copy & paste the content in a shell window. It is much better to store the code in a .ps1 file, and in PowerShell just call the script (by using the full path name to the script).

Pasting directly into PS console only makes sense if you do it line after line, and only if there is no error.

It is impossible that the Exchange Management Shell behaves exactly the same. The Exchange snap-in is loaded, the environment prepared for Exchange, including some convinience commands. The only issue which should come up is an error message stating the Exchange snap-in is already loaded.
You can always check for registered snap-ins with Get-PsSnapin -Registered. It should show the Exchange one.
0
 

Author Comment

by:Jerry Seinfield
ID: 39809450
Hi Qlemo

I did save the script and run as ps1, still no luck. same errors

Any ideas?

why most cmdlet are not recognized as cmdlet by the powershell console?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39810007
Please type Get-PsSnapin -Registered in a PS console, and see if you can spot Exchange. I don't get what happens here.
0
 

Author Comment

by:Jerry Seinfield
ID: 39822841
Hi Qlemo,

I ran get-psnapin-registered in a ps console from a domain controller and from an exchange servers. please see the attached docs
fromdcfromexchangeserver
0
 

Author Comment

by:Jerry Seinfield
ID: 39822843
Any ideas?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39822907
You have the Quest ActiveRole (AD) Cmdlets on the DC only, and the Exchange ones only on Exchange server. As-is, you need to run the commands on the Exchange server, and replace my first two code lines with
Add-PsSnapin Microsoft.Exchange.Management.Powershell.E2010

Open in new window

That should do.
0
 

Author Comment

by:Jerry Seinfield
ID: 39823045
Here are the results

All the txt files were created now, but the html page was not created. The email was sent fine, but see the format below and notice any of the items contain anyfinalerror values, please see also attached screen shoot with the errors displayed

DAG
DAGNetwork
MdbCopy
MdbCopy2
MDB
Replication Health
MSX Status
MB Server Status
DC
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39823398
I don't understand what you try to say here:
The email was sent fine, but see the format below and notice any of the items contain any values, please see also attached screen shoot with the errors displayed
The HTML part indeed contains a typo, I forgot to remove the title option, which does not work with -fragment:
Add-PsSnapin Microsoft.Exchange.Management.Powershell.E2010

function Set-Report (
  [parameter(ValueFromPipeline=$true)] $obj,
  [parameter(Position=0)] $file,
  [parameter(Position=1)] $title
)
{
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertTo-Html -Fragment
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body $body -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39823996
Thanks qlemo

The issue of cannot convert to html is gone, but a new issue resurfaces

please see attached screen shoot. The email also was not sent this time, and it used to work before i guess is because the new issue

Can you please also clarify what type of file is .txtm?

The script is generating a file name srv.20140131.txtm. see line code below

$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'

error6
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39824320
Yes, that is a consequence of the convert to HTML working now :/. Stupid me, of course you need to join the multiple strings (one string per line) to a single string before sending as mail, that is a requirement of Send-MailMessage which I tend to forget each time. Last line should be
Send-MailMessage -Body ($body -join "`n") -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 39826467
Hi Qlemo,

The Script worked like a rock, however the format of the html page displayed on the email is wrong. I have attached a MSG file with the information displayed on the email, you can open the file with Microsoft outlook and you will see

Any ideas on why the information is being displayed on that format?
Exchange-Stats-Report.msg
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39826514
There are several issues. Too many properties to nicely show on a table, properties not expanding (so you don't see the content, but some type info), and such.

Creating a proper HTML report for each object is more complex than you should think. There is no direct way to do a format-list into HTML, sadly.
0
 

Author Comment

by:Jerry Seinfield
ID: 39826570
Thanks Qlemo,

Is there an option to export all the txt objects into a CSV file, and use format-list? I mean, just wonder if we could export all reports [txt files] onto a single master csv report
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39827010
No, there is no direct way to have a single CSV contain all data. A CSV will look more like the HTML report, but only for the first data, and so is even worse.

Opposed to what I've told before, we have an option to make the HTML output look more like the format-list - but not completely, because only one level of objects will be resolved. That is, if a property contains a more complex object, you will see only the type name, not the object data. But honestly, it doesn't make much sense to dump all data into an email. You should monitor selected properties only, or at least exclude those you are certainly not interested in. You would do that similar to this:
$body += Get-SomeStats | select -Exclude VeryUninterestingProperty, AnotherExcludedOne | Set-Report c:\SomeStats.txt 'SomeStats'

Open in new window

The new code (without excluding properties) looks like so:
Add-PsSnapin Microsoft.Exchange.Management.Powershell.E2010

function Set-Report (
  [parameter(ValueFromPipeline=$true)] $obj,
  [parameter(Position=0)] $file,
  [parameter(Position=1)] $title
)
{
  $obj |  fl * > ($file -replace '\.', ('.'+(get-date -format 'yyyyMMdd')+'.'))
  "<h2>$title</h2>"
  $obj | convertTo-Html -Fragment -As List
}

$body = Get-DatabaseAvailabilityGroup -Status | Set-Report c:\dag.txt 'DAG'
$body+= Get-DatabaseAvailabilityGroupNetwork | Set-Report c:\dagNetwork.txt 'DAGNetwork'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\MdbCopy.txt 'MdbCopy'
$body+= Get-MailboxDatabase| Get-MailboxDatabaseCopyStatus | Set-Report c:\mdbcopy2.txt 'MdbCopy2'
$body+= Get-MailboxDatabase -Status | Set-Report c:\mdb.txt 'MDB'
$body+= Get-Mailboxserver | where {$_.DatabaseAvailabilityGroup -ne $null} | Test-ReplicationHealth | Set-Report c:\rphealth.txt 'Replication Health'
$body+= Get-ExchangeServer -Status | Set-Report c:\srv.txtm 'MSX Status'
$body+= Get-MailboxServer -Status | Set-Report c:\mbsrv.txt 'MB Server Status'
$body+= Get-DomainController | Set-Report c:\dc.txt 'DC'

Send-MailMessage -Body ($body -join "`n") -BodyAsHtml -SmtpServer mx.domain.com -From admin@domain.com -To admin@domain.com -Subject 'Exchange Stats Report'

Open in new window

The only difference is in the convertTo-Html line, where I added the -As List option, which creates a list like layout instead of a table like one.
0
 

Author Comment

by:Jerry Seinfield
ID: 39827794
Qlemo, the latest code basically is what i was looking for. Many thanks for your patience and help
0
 

Author Closing Comment

by:Jerry Seinfield
ID: 39827795
Excellent help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using O365 REST API's with PowerShell 3 36
size of file 1 24
Export AD group members. 1 28
output in HTML format powershell 6 23
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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