Extract Data from Custom Properties

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Wallace Lima Wallace Lima 2 years, 2 months ago.

  • Author
    Posts
  • #19370
    Profile photo of Wallace Lima
    Wallace Lima
    Participant

    Hello guys
    I have tried some approaches that I have saw here on forum, but I´m stuck on script as follow:
    the parameter -ExpandProperty not work to isolate data for html.
    If someone has already pass through this, any help will welcome
    thanks for attention, sorry for any misspelling
    see ya

    $computer = "localhost"
    
    $Body = "
            BODY{background-color:#eeeeee;}
            TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
            TH{text-align:center;width:140px; border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#38eeff}
            TD{text-align:center;border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}
            
             Disk Space Report: $DateComputerDiskSpace AvailablePercentStatus"
    
    $total_disk = Get-WmiObject -class Win32_LogicalDisk -computername $computer -filter "drivetype=3" | select @{label='Tamanho do Disco (GB)';expression={$_.Size / 1GB -as [int]}}
       
            $space_free = Get-WmiObject -class Win32_LogicalDisk -computername $computer -filter "drivetype=3" | select @{label='Espaco Livre (MB)';expression={$_.FreeSpace / 1MB -as [int]}}
       
            $percent_free = Get-WmiObject -class Win32_LogicalDisk -computername $computer -filter "drivetype=3" | select @{label='% Livre';expression={$_.FreeSpace / $_.Size * 100 -as [int]}}
            
    
    $Body +=  "$computer$total_disk$space_free$percent_free$ServerStatus"
    
    $Body += ""
    
    $body | out-file c:\temp\body.html
    
    Invoke-Expression C:\temp\body.html
    
    

    thank you very much

  • #19373
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You're taking the wrong approach, here. -ExpandProperty isn't meant to produce HTML, and nothing in your script is producing HTML.

    $disks = Get-WmiObject -class Win32_LogicalDisk -computername $computer -filter "drivetype=3" |
            select @{label='Tamanho do Disco (GB)';expression={$_.Size / 1GB -as [int]}},
                   @{label='Espaco Livre (MB)';expression={$_.FreeSpace / 1MB -as [int]}},
                   @{label='% Livre';expression={$_.FreeSpace / $_.Size * 100 -as [int]}}
    

    You query only once, and use one Select-Object to create the output you want. Keep in mind that $disks CAN have multiple objects in it, though.

    $fragment = $disks | ConvertTo-HTML -Fragment -As Table -PreContent "

    Disk Report

    " | Out-String

    Will convert all of the disks into an HTML table. This is just a fragment, and can be made into the body of an HTML page. This technique is useful for when you want to make HTML reports that have multiple sections.

    ConvertTo-HTML -Body $fragment | Out-File report.html
    

    Read "Creating HTML Reports in PowerShell" (select Resources from this site's main menu, then Ebooks). It covers this in a lot more detail. My example is just meant to be a quick example; the ebook explains much better, and also provides an EnhancedHTML2 module that provides for many more formatting options.

  • #19404
    Profile photo of Wallace Lima
    Wallace Lima
    Participant

    thank you very much Don, I´m already following "Creating HTML Reports in PowerShell"

You must be logged in to reply to this topic.