0

我获得了 BIOS 数据并将其保存在 HTML 文件中,但我不希望所有数据都在文件中,我还需要对其进行格式化,以便它可以满足我的要求。

代码:

$bios = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2"
[string]$body = $bios | ConvertTo-Html -As List| Out-File c:/d/d/Test.htm
4

2 回答 2

0

尝试这个:

$freeSpace = (gwmi Win32_logicaldisk -Filter "DeviceID = 'C:'").FreeSpace

gwmi Win32_BIOS `
  | select PSComputerName,Manufacturer,SerialNumber,Version,
      @{n="AvailableSpace";e={[int]($freeSpace / 1MB)}} `
  | ConvertTo-Html `
  | Out-File "C:/d/d/Test.htm"
于 2013-07-15T18:42:39.453 回答
0

因此,根据评论中的讨论,我认为您正在寻找这样的东西:

function GetCompInfoWork 
{
   param (
     [string]$computername,[string]$logfile
     )
    $os = Get-WmiObject win32_operatingsystem -ComputerName $computername
    $bios = Get-WmiObject win32_bios -ComputerName $computername
    $disk = Get-WmiObject win32_logicalDisk -Filter "DeviceID= 'C:'" `
    -computername $computername

    $obj = New-Object -TypeName PSObject

    $obj | Add-Member -MemberType NoteProperty `
        -Name ComputerName -Value ($os.csname)
    $obj | Add-Member -MemberType NoteProperty `
        -Name Manufacturer -Value ($bios.manufacturer)
    $obj | Add-Member -MemberType NoteProperty `
        -Name SysDriveFree -Value ($disk.freespace / 1GB -as [int])
    $obj | Add-Member -MemberType NoteProperty `
        -Name SerialNumber -Value ($bios.serialnumber)
    $obj | Add-Member -MemberType NoteProperty `
        -Name Version -Value ($bios.version)            
    Write-Output $obj
}
function Get-CompInfo 
{
  param ([string[]]$computername,[string]$logfile )

  BEGIN
  {
    $usedParamater = $False
    if ($PSBoundParameters.ContainsKey('computername')) {
        $usedParamater = $True
        }
  }
  PROCESS {
    if ($usedParamater) 
    {
        foreach ($computer in $computername)
        {
            Getcompinfowork -computername $computer `
            -logfile $logfile
        }
    }          
    else 
    {
        Getcompinfowork -computername $_ `
        -logfile $logfile
    }

  }
  END {}
}

Get-CompInfo -computername localhost | ConvertTo-Html | Out-File C:\Output.html
于 2013-07-15T18:54:02.050 回答