Problem with an array and the html output
Posted: Sun Jul 12, 2015 11:24 pm
Hello,
i have a problem with an array. When i create a html output from the script i have some double entrys and i dont know why.
Here is the script:
foreach ($server in $exchangeservers)
{
$disks = gwmi -query "SELECT Caption,VolumeName,Size,Freespace,DeviceID FROM win32_logicaldisk WHERE DriveType=3" -computer $Server -ErrorAction 'SilentlyContinue'
$diskinfo = @()
foreach ($disk in $disks)
{
[string]$g = [char]9608
$deviceID = $disk.DeviceID;
$volName = $disk.VolumeName;
$sizeGB = $disk.Size/1GB -as [int];
$freespaceGB = $disk.FreeSpace/1GB -as [int];
$percentFree = [Math]::Round(($freespaceGB / $sizeGB) * 100, 2);
$usedSpaceGB = $sizeGB - $freeSpaceGB;
$color = $whiteColor;
$UsedPer = (($SizeGB - $FreespaceGB)/$SizeGB) * 100
$UsedGraph = $g * ($UsedPer/2)
$FreeGraph = $g * ((100 - $UsedPer)/2)
#I'm using place holders for the < and > characters
$Graph = "<Font color=Red>{0}</Font><Font Color=Green>{1}</font>" -f $usedGraph, $FreeGraph
# Set background color to Orange if just a warning
if ($percentFree -lt $percentWarning)
{
$color = $orangeColor
# Set background color to Orange if space is Critical
if ($percentFree -lt $percentCritcal)
{
$color = $redColor
}
}
$diskobj = New-Object PSObject
$diskObj | Add-Member NoteProperty -Name "DeviceID" -Value $deviceID
$diskObj | Add-Member NoteProperty -Name "VolumeName" -Value $volName
$diskObj | Add-Member NoteProperty -Name "Size" -Value $sizeGB
$diskObj | Add-Member NoteProperty -Name "FreeSize" -Value $freeSpaceGB
$diskObj | Add-Member NoteProperty -Name "Used" -Value $usedSpaceGB
$diskObj | Add-Member NoteProperty -Name "Percent" -Value $percentFree
$diskObj | Add-Member NoteProperty -Name "Graph" -Value $Graph
$diskinfo += $diskObj
}
Write-Host $diskobj
$diskreport = $diskreport + $diskinfo
}
#Exchange Server Disk Report Table Header
#region Diskreport
$diskhtmlheader = "<h1 style=""font-size: 14px""<strong>Diskspace</strong></h1>"
foreach ($s in $exchangeservers)
{
$sname = $s.name
$diskhtmltableheader += "
<table>
<tr>
<th>$sname</th>
</tr>
<tr>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Device ID</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Volume Name</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Size (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Free Size (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Used (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Percent</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px""></th>
</tr>"
#Exchange Server Disk Report Table
$diskspacehtml = $diskspacehtml + $diskhtmltableheader
foreach ($reportline in $diskreport)
{
$htmltablerowdisk = "<tr>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.DeviceID)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.VolumeName)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Size)</td>"
$htmltablerowdisk += "<td bgcolor=""$color"" style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.FreeSize)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Used)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Percent)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Graph)</td>"
$htmltablerowdisk += "</tr>"
$diskspacehtml = $diskspacehtml + $htmltablerowdisk
}
}
$diskspace = $diskhtmlheader + $diskspacehtml + "</table>"
#endregion
Attached you can see the html output.
Thx
Greets
Alexander
i have a problem with an array. When i create a html output from the script i have some double entrys and i dont know why.
Here is the script:
foreach ($server in $exchangeservers)
{
$disks = gwmi -query "SELECT Caption,VolumeName,Size,Freespace,DeviceID FROM win32_logicaldisk WHERE DriveType=3" -computer $Server -ErrorAction 'SilentlyContinue'
$diskinfo = @()
foreach ($disk in $disks)
{
[string]$g = [char]9608
$deviceID = $disk.DeviceID;
$volName = $disk.VolumeName;
$sizeGB = $disk.Size/1GB -as [int];
$freespaceGB = $disk.FreeSpace/1GB -as [int];
$percentFree = [Math]::Round(($freespaceGB / $sizeGB) * 100, 2);
$usedSpaceGB = $sizeGB - $freeSpaceGB;
$color = $whiteColor;
$UsedPer = (($SizeGB - $FreespaceGB)/$SizeGB) * 100
$UsedGraph = $g * ($UsedPer/2)
$FreeGraph = $g * ((100 - $UsedPer)/2)
#I'm using place holders for the < and > characters
$Graph = "<Font color=Red>{0}</Font><Font Color=Green>{1}</font>" -f $usedGraph, $FreeGraph
# Set background color to Orange if just a warning
if ($percentFree -lt $percentWarning)
{
$color = $orangeColor
# Set background color to Orange if space is Critical
if ($percentFree -lt $percentCritcal)
{
$color = $redColor
}
}
$diskobj = New-Object PSObject
$diskObj | Add-Member NoteProperty -Name "DeviceID" -Value $deviceID
$diskObj | Add-Member NoteProperty -Name "VolumeName" -Value $volName
$diskObj | Add-Member NoteProperty -Name "Size" -Value $sizeGB
$diskObj | Add-Member NoteProperty -Name "FreeSize" -Value $freeSpaceGB
$diskObj | Add-Member NoteProperty -Name "Used" -Value $usedSpaceGB
$diskObj | Add-Member NoteProperty -Name "Percent" -Value $percentFree
$diskObj | Add-Member NoteProperty -Name "Graph" -Value $Graph
$diskinfo += $diskObj
}
Write-Host $diskobj
$diskreport = $diskreport + $diskinfo
}
#Exchange Server Disk Report Table Header
#region Diskreport
$diskhtmlheader = "<h1 style=""font-size: 14px""<strong>Diskspace</strong></h1>"
foreach ($s in $exchangeservers)
{
$sname = $s.name
$diskhtmltableheader += "
<table>
<tr>
<th>$sname</th>
</tr>
<tr>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Device ID</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Volume Name</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Size (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Free Size (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Used (GB)</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px"">Percent</th>
<th style=""border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;font-size: 12px""></th>
</tr>"
#Exchange Server Disk Report Table
$diskspacehtml = $diskspacehtml + $diskhtmltableheader
foreach ($reportline in $diskreport)
{
$htmltablerowdisk = "<tr>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.DeviceID)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.VolumeName)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Size)</td>"
$htmltablerowdisk += "<td bgcolor=""$color"" style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.FreeSize)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Used)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Percent)</td>"
$htmltablerowdisk += "<td style=""border: 1px solid black; padding: 5px; font-size: 12px"">$($reportline.Graph)</td>"
$htmltablerowdisk += "</tr>"
$diskspacehtml = $diskspacehtml + $htmltablerowdisk
}
}
$diskspace = $diskhtmlheader + $diskspacehtml + "</table>"
#endregion
Attached you can see the html output.
Thx
Greets
Alexander