Search code examples
powershellpowershell-3.0powershell-ise

Obtaining Required columns in HTML output in Powershell


I obtained the BIOS data and saved it in HTML file but i don't want all the data to be in the file and i also need to format it so that it could suite my requirement.

Code:

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

Solution

  • So based on the discussion in the comments, I think you are looking for something like this:

    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