HTML Formatting

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

  • Author
    Posts
  • #16655
    Profile photo of H Man
    H Man
    Participant

    The below script works great the only thing I would like to change is the HTML tables that are generated in the .html file are going vertically , is there any way to have the 4 different tables in the file be horizontal?

     
    $head = @"
    
    body 
    { 
     background-color:#FFFFFF;
     font-family:Tahoma;
     font-size:12pt; 
    }
    td, th 
    { 
     border:1px solid black; 
     border-collapse:collapse; 
    }
    th 
    {
     color:white;
     background-color:black; 
    }
    table, tr, td, th { padding: 5px; margin: 0px }
    table { margin-left:50px; }
    .danger {background-color: red}
    .warn {background-color: yellow}
    
    
    "@
    
    
    $Reboot      =   Get-WmiObject -Class Win32_OperatingSystem -ComputerName $s.computername |Select-Object CSName,@{ Name = "Last Restarted On" ; Expression = { $_.Converttodatetime( $_.LastBootUpTime ).ToShortTimeString() } }
    #create an xml document from the HTML fragment
    [xml]$RBhtml = $Reboot   | ConvertTo-Html -fragment
            
    #check each row, skipping the TH header row
    for ($i=1;$i -le $RBhtml.table.tr.count-1;$i++) {
      $class = $RBhtml.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($RBhtml.table.tr[$i].td[-1] -as [string]) -ne '11:00 PM') {                                          
        $class.value = "danger"  
        $RBhtml.table.tr[$i].Attributes.Append($class) | Out-Null
      }
      
    } 
    $date = (date).AddDays(-1).ToString('MMMM.d.yyyy')
    #create the final report from the innerxml which should be html code
    $RebootBody = @"
    Last Reboot as of $date
    $($RBhtml.innerxml)
    "@
    
    
    
    $hotfix = Invoke-Command -Session $s  -ScriptBlock {  
    $Result = Get-Hotfix | where {$_.hotfixid -eq 'KB2617858'}
    if ($Result) {
    
    New-Object PSObject -Property @{Computer = hostname; Installed = $true } 
    
    
    
    } else {
    New-Object PSObject -Property @{Computer = hostname; Installed = $false}
    
    
    } }
    
    #create an xml document from the HTML fragment
    [xml]$HFhtml = $hotfix | select computer,installed  | ConvertTo-Html -fragment
    
    #check each row, skipping the TH header row
    for ($i=1;$i -le $HFhtml.table.tr.count-1;$i++) {
      $class = $HFhtml.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($HFhtml.table.tr[$i].td[-1] -as [string]) -ne 'True') {                                          
        $class.value = "danger"  
        $HFhtml.table.tr[$i].Attributes.Append($class) | Out-Null
      }
      
    } 
    $date = (date).ToString('MMMM.d.yyyy')
    #create the final report from the innerxml which should be html code
    $HotfixBody = @"
    HotFix Check Date: $date
    $($HFhtml.innerxml)
    "@
    
    
     $UAC= Invoke-Command -Session $s  -ScriptBlock { 
    #Check-Report
    $EnableLUA =  gp  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' 
    $UAC = $EnableLUA.EnableLUA
    $Result = $UAC| where {$_.EnableLUA -eq '0'}
    if ($Result) {
        New-Object PSObject -Property @{Computer = hostname; UACEnabled = $true}
    } else {
        New-Object PSObject -Property @{Computer = hostname; UACEnabled = $false}
    }
    
    }
    
    
    #create an xml document from the HTML fragment
    [xml]$UAChtml =  $UAC| select computer,UACEnabled  | ConvertTo-Html -fragment
    
    
    for ($i=1;$i -le $UACHFhtml.table.tr.count-1;$i++) {
      $class = $UACFhtml.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($UAChtml.table.tr[$i].td[-1] -as [string]) -ne 'True') {                                          
        $class.value = "danger"  
        $UAChtml.table.tr[$i].Attributes.Append($class) | Out-Null
      }
      
    } 
    $date = (date).ToString('MMMM.d.yyyy')
    #create the final report from the innerxml which should be html code
    $UACBody = @"
    UAC Enabled Check: $date
    $($UAChtml.innerxml)
    "@
    
    
    
    
    
     $firewall =  Invoke-Command -Session $s  -ScriptBlock { 
    
    
    $firewall =netsh advfirewall show allprofiles | Select-String "state"
    $profiles = $firewall | foreach {$_.Line.Substring(15)}
    $data = @() 
    
    $profiles |  foreach {
    
    
    $OutputObj = New-Object -TypeName PSobject
    $OutputObj | Add-Member -MemberType NoteProperty -Name Computer -Value $env:COMPUTERNAME              
    $OutputObj | Add-Member -MemberType NoteProperty -Name Domain -Value $profiles[0].Split()[-1]
    $OutputObj | Add-Member -MemberType NoteProperty -Name Private -Value $profiles[1].Split()[-1]
    $OutputObj | Add-Member -MemberType NoteProperty -Name Public -Value $profiles[2].Split()[-1]
    
    
    $data  += $OutputObj
    
    WRITE $DATA
    
    } }
    
    #create an xml document from the HTML fragment
    [xml]$Firewallhtml =   $firewall   | select -Property computer,domain,private,public -Unique | sort computer | ConvertTo-Html -fragment
    
    #check each row, skipping the TH header row
    for ($i=1;$i -le $Firewallhtml.table.tr.count-1;$i++) {
      $class = $Firewallhtml.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($Firewallhtml.table.tr[$i].td[0] -as [string]) -eq 'ON') {                                          
        $class.value = "danger"  
       $Firewallhtmll.table.tr[$i].Attributes.Append($class) | Out-Null
      }
      elseif (($Firewallhtml.table.tr[$i].td[-1] -as [string]) -eq 'ON') {                                               
        $class.value = "warn"    
        $Firewallhtml.table.tr[$i].Attributes.Append($class) | Out-Null
      }
    }
    $date = (date).ToString('MMMM.d.yyyy')
    #create the final report from the innerxml which should be html code
    $FirewallBody = @"
    Firewall State Check: $date
    $($Firewallhtml.innerxml)
    "@
    
    
    $date = Get-Date -Format d.MMMM.yyyy
    $OutputDir = "$env:TEMP\SystemTweaks"
    $File = "Hotfix-FireWall-Reboot-UAC-2" + $date +".html" 
    $OutputFile = Join-Path $OutputDir $file
    
    $Report = ConvertTo-Html -Title "System Check Report" `
                             -Head $head `
                             -Body "$HotfixBody $RebootBody $UACBody $FirewallBody"
    $Report | Out-File $OutputFile -Encoding ascii  -Force ; Invoke-Expression $OutputFile
    
     
  • #16656
    Profile photo of Don Jones
    Don Jones
    Keymaster

    HTML doesn't make it easy to do vertical side-by-side tables. You'd have to get into CSS positioning, which is a little out of scope for here. It'll involve doing some hand-coding of HTML, since you'll have to wrap the tables in a DIV, giving them an ID attribute, so that you can refer to them from the CSS.

  • #16657
    Profile photo of H Man
    H Man
    Participant

    Ok thank you for the response and info

You must be logged in to reply to this topic.