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
Problem with an array and the html output
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- alwo23@hotmail.com
- Posts: 28
- Last visit: Tue Jun 06, 2023 2:43 am
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Problem with an array and the html output
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:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
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:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
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
*** Make sure you do not post any licensing information ***