Putting output into table

Hi

Got the following script which works great but would like to put it into a table when I receive it by email.  I would like to also highlight certain lines that begin with DAG01, DAG04, DAG15 etc.

I've been playing around with the table but cant get it working.  Any help would be great thanks

$servernames = @('GRPMBX1001', 'GRPMBX1002', 'GRPMBX2001')
$smtpsettings = @{
	To = david.Test@test.com"
	From = "ExchangeStats@Email.com"
	Subject = "Exchange Server Space Report for $((Get-Date).ToShortDateString())"
	SmtpServer = "SMTPRELAY.test.co.uk"
}
$Data = @()
foreach ($Server in $Servernames)
{
	$EX = Get-ExchangeServer -Identity $Server
	
	$DBs = Get-MailboxDatabase -Status -Server $EX
	
	foreach ($DB in $DBs)
	{
		# Retrieve Volumes
		$VolData = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$((Split-Path $DB.EdbFilePath.PathName).Replace("\", "\\"))\\'"
		$VolLogs = Get-WmiObject Win32_Volume -ComputerName $Server -Filter "name = '$($DB.LogFolderPath.PathName.Replace("\", "\\"))\\'"
		
		# Process Free percent
		try { $DataFreePercent = "{0:N1}" -f ($VolData.FreeSpace / $VolData.Capacity * 100) }
		catch { $DataFreePercent = "{0:N1}" -f -99.9 }
		try { $LogFreePercent = "{0:N1}" -f ($VolLogs.FreeSpace / $VolLogs.Capacity * 100) }
		catch { $LogFreePercent = "{0:N1}" -f -99.9 }
		
		
		$Props = @{
			Server = $Server
			DAG = $DB.Name
            Path = $DB.EdbFilePath
	        DAGEDBSize = "{0:N2}" -f ($DB.DatabaseSize.ToBytes() / 1GB)
			DAGSizeInUse = "{0:N2}" -f (($DB.DatabaseSize.ToBytes() - $DB.AvailableNewMailboxSpace.ToBytes()) / 1GB)
			DAGCopyState = ($DB | Get-MailboxDatabaseCopyStatus | Select-Object -ExpandProperty Status) -join " / "
			LUNCapacity = "{0:N2}" -f ($VolData.Capacity / 1GB)
			DataFree = "{0:N2}" -f ($VolData.FreeSpace / 1GB)
			DataFreePercent = "$($DataFreePercent)%"
            Mailboxes = (Get-Mailbox -resultsize unlimited -Database $db).count
			}
		
		$Data += New-Object PSObject -Property $Props
	}
}
$Body = ($Data | Sort-Object DAG, Server | Select-Object Server, DAG, Path, DAGEDBSize, DAGSizeInUse, DAGCopyState, LUNCapacity, DataFree, DataFreePercent, Mailboxes | ConvertTo-Html) -join "`n"
Send-MailMessage @smtpsettings -Body $Body -BodyAsHTML

August 19th, 2015 9:35am

Hi SaintsDT,

may be this helps you a little

Link

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 10:06am

Thanks I've tried that a several others but cant get it working
August 19th, 2015 10:09am

Try first redirecting it simply to file:

$Data | Sort-Object DAG, Server | Select-Object Server, DAG, Path, DAGEDBSize, DAGSizeInUse, DAGCopyState, LUNCapacity, DataFree, DataFreePercent, Mailboxes | ConvertTo-Html | Out-File C:\Temp\Test.htm

Is the table shown correctly?

May be also with Format-Table:

$Data | Sort-Object DAG, Server | Select-Object Server, DAG, Path, DAGEDBSize, DAGSizeInUse, DAGCopyState, LUNCapacity, DataFree, DataFreePercent, Mailboxes | ft | ConvertTo-Html | Out-File C:\Temp\Test.htm

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 10:18am

Thanks but I dont want to output to html file but include the table in the body of the email.  As it is now but in a table format

thanks again

August 19th, 2015 10:22am

Thanks but I dont want to output to html file but include the table in the body of the email.  As it is now but in a table format

thanks again

Yeah sure - i wanted only to test if something went wrong by sending it via Mail.

The join with `n could be the problem:

$Body = $Data | Sort-Object DAG, Server | Select-Object Server, DAG, Path, DAGEDBSize, DAGSizeInUse, DAGCopyState, LUNCapacity, DataFree, DataFreePercent, Mailboxes | ConvertTo-Html


Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 10:32am

Simple:

$Body=$Data |
    Sort-Object DAG, Server | 
    Select-Object Server, DAG, Path, DAGEDBSize, DAGSizeInUse, DAGCopyState, LUNCapacity, DataFree, DataFreePercent, Mailboxes |
    ConvertTo-Html |
    Out-String

August 19th, 2015 1:29pm

ConvertTo-Html creates a table by default.  What are you calling a table?

Here is the output of this: "dir c:\ |select name, size, fullname|Convertto-Html|Out-String"

This is a table.

<title>HTML TABLE</title>
Name size FullName
Acer C:\Acer
All Resources C:\All Resources
Chocolatey C:\Chocolatey
config C:\config
Dolby PCEE4 C:\Dolby PCEE4
inetpub C:\inetpub
JeaDemo C:\JeaDemo
MSSQL C:\MSSQL
od C:\od
PerfLogs C:\PerfLogs
PortQryV2 C:\PortQryV2
Prep C:\Prep
Program Files C:\Program Files
Program Files (x86) C:\Program Files (x86)
Scripts C:\Scripts
SQL Server 2000 Sample Databases C:\SQL Server 2000 Sample Databases
temp C:\temp
temp2 C:\temp2
temp3 C:\temp3
test C:\test
Users C:\Users
Windows C:\Windows
Windows.old C:\Windows.old
HPFWUpdate.log C:\HPFWUpdate.log
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 6:33am

Yes it works in out-put to html file.  But that isnt what I asked.

I would like an table in the body of an email

Thanks

August 20th, 2015 6:47am

Hi thanks for replying but this isnt what I'm asking or want.

I would like an table within the body of of an email.  something like

$style = "< style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "< /style>"

But it doesnt work when I add it to my script

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 3:27am

that is not a table that is a style sheet.  It will not produce anything.

In Powershell we would do this:

$style=@'
    < style type="text/css">
        BODY{font-family: Arial; font-size: 10pt;}
        TABLE{border: 1px solid black; border-collapse: collapse;}
        TH{border: 1px solid black; background: #dddddd; padding: 5px; }
        TD{border: 1px solid black; padding: 5px; }
     < /style>
'@

$emai=dir c:\ |
   select name, size, fullname|
   ConvertTo-Html -header $style |
   Out-String"

August 21st, 2015 3:36am

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

Other recent topics Other recent topics