如何在PowerShell中将Foreach函数中的数据存储在Html文件中并获取物理内存 [英] How to store data from foreach function in HTML file in powershell and get Physicall ram

查看:26
本文介绍了如何在PowerShell中将Foreach函数中的数据存储在Html文件中并获取物理内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为存储网络中系统的BIOS信息的每个文件编写了一个,结果将显示在我的控制台上,但我希望它们按顺序显示在一个HTML文件中。

编码:

  $arrComputers = get-Content -Path "C:Computers.txt"
    foreach ($strComputer in $arrComputers)
    {
        $colItems = get-wmiobject -class "Win32_BIOS" -namespace "rootCIMV2" `
        -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
   }


    }

您能帮我将上述所有数据保存在HTML中吗

推荐答案

您需要查看ConvertTo-Htmlcmdlet。

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

另一种基于运算符更新的方法:

$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:	est4.html

这篇关于如何在PowerShell中将Foreach函数中的数据存储在Html文件中并获取物理内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆