Question

I have written a code snippet and I have incorporated write host in it i want both write host and convert html to run for this snippet can any one help me with that.

 $arrComputers = get-Content -Path "C:\Computers.txt"
    foreach ($strComputer in $arrComputers)
    {
        $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" `
        -computername $strComputer
       foreach ($objItem in $colItems)
       {
         write-host "Computer Name: " $strComputer
          write-host "BIOS Version: " $objItem.BIOSVersion
      }

       $colItems1 = get-wmiobject -class Win32_logicaldisk -Filter "DeviceID = 'C:'" -computername $strComputer
       foreach ($objItem1 in $colItems1)
       {
        $e=$objItem1.freeSpace/1GB
         write-host "Total Space:  " $e
         }

        $colItems4 = Get-WMIObject -class Win32_PhysicalMemory  -computername $strComputer
      $colItems5=$colItems4 | Measure-Object -Property capacity -Sum 
      foreach ($objItem4 in $colItems5)
   {
      $e4=$colItems5.Sum/1GB
      write-host "Memory :  " $e4
   }


    }
Était-ce utile?

La solution

You can use the -Fragment parameter.

$pcName = "Computer Name: $strComputer" | ConvertTo-HTML -Fragment;
$biosV = "BIOS Version: $objItem.BIOSVersion" | ConvertTo-HTML -Fragment;

ConvertTo-HTML -Body "$pcName $biosV" -Title "List of Computers" |  Out-File c:\listofcomputers.html

Just create variables after the Write-Host with the same content and use the converTo-HTML at the end of the script.

This way allows you to style your HTML output too by using the param tag or even table tags to have a better layout then a clean sterile layout.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top