0

I have written a for each file which stores the BIOS information of the systems in a network and the result is being displayed on my console but I want them to be in a HTML file in an order.

Code:

  $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
   }


    }

Can you please help me in saving all the above data in HTML

2
  • what is $RamCal? You need to be a local administrator to be able to access WMI. Commented Jul 16, 2013 at 15:51
  • Can you please check the updated question Commented Jul 16, 2013 at 18:24

1 Answer 1

0

You need to look at the ConvertTo-Html cmdlet.

Get-WmiObject -Class Win32_BIOS -ComputerName localhost,$env:COMPUTERNAME | 
Select PSComputerName,Version,SerialNumber | 
ConvertTo-Html | 
Out-File c:\test3.html

Another method based on OPs update:

$arrComputers = get-Content -Path "C:\Computers.txt"

$arrComputers | ForEach-Object { Get-WMIObject -Class Win32_BIOS -ComputerName $_ } | 
Select PSComputerName, Version, Manufacturer | 
ConvertTo-Html | 
Out-File C:\test4.html
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you Ravikanth :) for just one system I have an idea how to go about but I have a problem when I use foreach function , I am confused how to send the obtained results to the HTML file.
Edited. Check that. You don't need a foreach loop. You can do all that in the pipeline.
hmm! using Write-Host is the first mistake. Second, you don't need foreach loop. I will update my answer.
Thank you soo much for your reply :) Can you please drop some light on my second doubt please
you need to be a local admin on the remote computer to access WMI classes.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.