Support Forums

Problem with an array and the html output

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
User avatar
alwo23@hotmail.com
Posts: 27
Joined: Sat Sep 28, 2013 1:56 am

Problem with an array and the html output

Postby alwo23@hotmail.com » 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

htmloutput.PNG
Output from the HTML File
htmloutput.PNG (20.69 KiB) Viewed 9229 times


Attached you can see the html output.
Thx
Greets
Alexander
User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

Problem with an array and the html output

Postby SAPIEN Support Forums » Sun Jul 12, 2015 11:24 pm

This is an automated post. A real person will respond soon.

Thank you for posting, alwo23@hotmail.com.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum:
If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
    1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

Return to “Windows PowerShell”

Who is online

Users browsing this forum: No registered users and 3 guests

cron