Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 178304

Formatting report

$
0
0

Hi All,

 

After getting the code right i am now having some issues with formatting in HTML, i have a couple of probably very simple issues and one maybe not so simple. Below is my code and attached is a screenshot, what basically happens is a list of servers are reported against if they exceed the specified resources the cells turn red, however since adding the additional cell coloring the format of the cells has gone all funny - not sure if this is because some of the guests in the text file dont exist yet..

1. I need to a line break after the First statement, i tried "`n" and <br/> but neither work

2. I also need to change the format of the title to be bold when i have added HTML formatting it doesn't work for me anyway.

3. Lastly the funny cell formats shown in the attached output only occurred once i added the elements to change the color.

 

Thanks in advance, i probably just need to walk away for a while, script needs tidying up as well.

 

#Start of Script

 

 

$Result = @()

foreach ($vm in Get-VM -Name $vmName)

 

 

{

 

 

   $Result += New-Object PSObject -Property @{

 

 

   ServerName = $vm.Name

 

 

   VMHost = $vm.VMHost.Name

 

 

   Powerstate = $vm.PowerState

 

 

   CPU = $vm.NumCpu

 

 

   Mem = $vm.MemoryGB

 

 

   UsedGB = [math]::Round($vm.ProvisionedSpaceGB, 0)

 

 

   }

 

 

}

 

 

 

 

$Result += New-Object PSObject -Property @{

 

 

   ServerName = 'Totals'

 

 

   VMHost = ''

 

 

   Powerstate = ''

 

 

   CPU = ($result | Measure-Object -Property CPU -Sum).Sum

 

 

   Mem = ($result | Measure-Object -Property Mem -Sum).Sum

 

 

   UsedGB = ($result | Measure-Object -Property UsedGB -Sum).Sum

 

 

}

 

 

#Start of html formatting

if($Result -ne $null)

{

$HTML = '<style type="text/css">

#Header{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;width:100%;border-collapse:collapse;}

#Header td, #Header th {font-size:14px;border:1px solid #006400;padding:3px 7px 2px 7px;}

#Header th {font-size:14px;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#006400;color:#fff;}

#Header tr.alt td {color:#000;background-color:#EAF2D3;}

</Style>'

 

 

    $HTML += "<HTML><BODY><Table border=1 cellpadding=0 cellspacing=0 id=Header>

<TR>

<TH><B>Server Name</B></TH>

<TH><B>VMHost</B></TD>

<TH><B>Power State</B></TD>

<TH><B>CPUs</B></TD>

<TH><B>Memory GB</B></TD>

<TH><B>Used Space</B></TH>

 

</TR>"

    Foreach($Entry in $Result){

 

if($Entry.Mem -gt $agreedMem)

{

$HTML += "<TR bgcolor=Red>"

}else

{

$HTML += "<TR>"

}

 

if($Entry.CPU -gt $agreedCPU)

{

$HTML += "<TR bgcolor=Red>"

}else

{

$HTML += "<TR>"

}

 

if($Entry.UsedGB -gt $agreedStr)

{

$HTML += "<TR bgcolor=Red>"

}else

{

$HTML += "<TR>"

}

 

 

 

$HTML += "

<TD>$($Entry.ServerName)</TD>

<TD>$($Entry.VMHost)</TD>

<TD>$($Entry.PowerState)</TD>

<TD>$($Entry.CPU)</TD>

<TD>$($Entry.Mem)</TD>

<TD>$($Entry.UsedGB)</TD>

 

</TR>"

    }

 

 

 

    $HTML += "</Table></BODY></HTML>"

 

 

$HTML | Out-File $OutputReport

}

 

 

 

 

 

 

#Start of email formatting

$body = write-output $header

$body += "`n write-output $header2 "

$body += [System.IO.File]::ReadAllText($OutputReport)

 

 

 

 

Send-MailMessage -To $to -From $from -Subject "Daily Checks - Dynamics Resource report" -Body $body -BodyAsHtml -SmtpServer $smtp

 

 

 

 

start-sleep -s 30

 

 

Remove-Item -Path $OutputReport -Force


Viewing all articles
Browse latest Browse all 178304

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>