Question : Powershell to HTML displays

Below is a code created within powergui.  When I execute the command from powergui the HTML display text that is easy to understand.  However, when I execute the command using the powershell console I get information that displays the same information in GUID format.  How can I get powershell to convert the output to text that is understandable?

$a = "<style>"
$a = $a + "BODY{background-color:honeydew;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:lawngreen}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegreen}"
$a = $a + "</style>"
$outData = @()
$Computers = 'server1', 'server2'
foreach ($comp in $Computers)
{
$Disks = Get-WMIObject -ComputerName $comp Win32_LogicalDisk | where {$_.Description -eq "Local Fixed Disk"}
foreach ($disk in $Disks)
{
$FreeSpace = ($disk.Freespace/1MB)
$Capacity = ($disk.Size/1MB)
$PercentFree = (($FreeSpace/$Capacity)*100)
add-member -InputObject $disk -MemberType NoteProperty -name FreePercent -value $PercentFree
$outdata = $outData + $disk
}
}
$percent = @{n="Percent Free";e={"{0:N}%" -f $_.FreePercent}}
$free = @{n="Free Space";e={"{0:N} GB" -f ($_.FreeSpace/1GB)}}
$total = @{n="Disk Size";e={"{0:N} GB" -f ($_.Size/1GB)}}
$outData | sort-object -property FreePercent | Select-Object SystemName,DeviceID,$free |ft | Sort-Object Systemname –Descending |ConvertTo-HTML -Head $a -Title "Exchange Dash Board"| Out-File C:\Scripts\Exchangedashboard.html


Answer : Powershell to HTML displays


Well... that script is a bit scary really... Care to give this one a try? Output may need a little work, deciphering that one is a bit of a hard task really.

A quick note on the Title, if you define a Head you must put the title there. The title lives in the head and the Title parameter has no effect is Head is used.

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
$Head = "
  <title>Exchange Dashboard</title>
  <style type='text/css'>
    body  { background-color: honeydew; }

    table { 
      border-width: 1px; 
      border-style: solid;
      border-color: black;
      border-collapse: collapse;
    }

    th    { 
      border-width: 1px; 
      padding: 0px; 
      border-style: solid; 
      border-color: black;
      background-color:lawngreen;
    }

    td    {
      border-width: 1px;
      padding: 0px;
      border-style: solid;
      border-color: black;
      background-color: palegreen
    }
  </style>"

$Computers = 'server1', 'server2'

$Computers | ForEach-Object {

  Get-WMIObject Win32_LogicalDisk -ComputerName $_ -Filter "DriveType=3" | 
    Select-Object `
      SystemName, Name,
      @{n='Free Space';e={ '{0:N}' -f ($_.FreeSpace / 1Gb) }},
      @{n='Disk Size';e={ '{0:N}' -f ($_.Size / 1Gb) }},
      @{n='Percent Free';e={ '{0:P2}' -f ($_.FreeSpace / $_.Size) }}
} | Sort-Object "Percent Free" -Descending | 
  ConvertTo-Html -Head $Head | 
  Out-File C:\Scripts\Exchangedashboard.html
Random Solutions  
 
programming4us programming4us