Hello the following is related to this email but I am stuck in rounding the numbers
Powershell/PowerCLI Dynamic Email Message Body
I am getting an email with the following info:
Datastore HealthCheck vCenter
Datastore Space Available
Datastore UsedGB Free GB Perc Free
name1 273.30078125 274.25 99%
name2 273.30078125 274.25 99%
name3 268.466796875 274.25 99%
name4 273.30078125 274.25 99%
Three things that I am stuck: First, the UsedGB value, woud like to have it with only two decimal points, instead of having 273.30078125, nice to have 273.30. Second I am not getting the right percentage. Third: How do i sort the the Perf Free values from the lowest to the bigger percentage? Thanks for your help
Code:
$msg.Subject = "vCenter Datastore Health CompanyvCenter" |
$array0 = @()
$array1 = @()
$array2 = @()
start-sleep 1
connect-VIServer $vcserver
$array0 += Get-Datastore | Select-Object -ExpandProperty Name
$array1 += Get-Datastore | Select-Object -ExpandProperty FreeSpaceGB
$array2 += Get-Datastore | Select-Object -ExpandProperty CapacityGB
$UsedSpace = [math]::round(($array2[$i] - $array1[$i]),2)
$PercFree = [math]::Round((100 * $array1[$i] / $array2[$i]),0)
$String0 = "$PercFree$Percent"
$i = 0
$j = 0
# Header
$msg.Body += "<FONT COLOR=black>Datastore HealthCheck CompanyvCenter</FONT><BR><BR>"
# Datastore header
$msg.Body += "<B><FONT COLOR=black>Datastore Space Available</FONT></B><BR>"
$msg.Body += "<B><FONT COLOR=black>Datastore</FONT></B><B><FONT COLOR=black> UsedGB</FONT></B>`
<B><FONT COLOR=black> Free GB</FONT></B>`
<B><FONT COLOR=black> Perc Free</FONT></B>"
# Datasores
0..($array0.Count-1) | %{
$msg.Body += "<BR><FONT COLOR=Black>" + $array0[$_]
$msg.Body += "</FONT> <FONT COLOR=Black>" + [math]::round(($array2[$_] - $array1[$_]),2)
#$msg.Body += "</FONT> <FONT COLOR=Black>" + $array1[$_]
$msg.Body += "</FONT> <FONT COLOR=Black>" + $array2[$_] + "</FONT>"
#$msg.Body += "</FONT> <FONT COLOR=Black>" + [math]::round(($array2[$_] - $array1[$_]),2) + "</FONT>"
$msg.Body += " <FONT COLOR=Black>" + [math]::Round((100 * $array1[$i] / $array2[$i]),0)+"$Percent"+"</FONT><BR>"}
$msg.Attachments.Add($att1)
$msg.IsBodyHTML = $true
$smtp.Send($msg)
$att1.Dispose()
Disconnect-VIServer $vcserver -Confirm:$false