在Powershell中获取HTML输出中的必需列

时间:2013-07-15 16:09:06

标签: powershell powershell-v3.0 powershell-ise

我获取了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

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分: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