Question

When I run the below code I get an error with Model Number in which the heading is not being displayed and one more thing is i am unable to get all the three of them in a sequence.

$arrComputers = get-Content -Path "C:\Desktop\Computers.txt"
    $e=$arrComputers | ForEach-Object {Get-WMIObject -Class Win32_BIOS -ComputerName $_ } |Select PSComputerName, Version,Manufacturer,Status,BIOSVersion,SerialNumber |ConvertTo-Html -fragment
     $e2=$arrComputers |ForEach-Object { get-wmiobject -class Win32_logicaldisk -Filter "DeviceID = 'C:'" -ComputerName $_ } | select freeSpace,size | ConvertTo-Html -fragment
      $e3=$arrComputers |ForEach-Object { get-wmiobject -class "Win32_ComputerSystem" -ComputerName $_ } | select Model| ConvertTo-Html -fragment

     ConvertTo-HTML -Body "$e $e2 $e3" -Title "List of Computers" |  Out-File C:\Users\Desktop\gf.html
Was it helpful?

Solution

Its a lot easier to make all of the WMI calls into a single object. It is much easier to handle formatting. I think I got everything that you were wanting:

function GetCompInfoWork 
{
param (
    [string]$computername,[string]$logfile
)
    $pc = Get-WmiObject Win32_ComputerSystem -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 PSCompName -Value ($bios.PSComputerName)

    $obj | Add-Member -MemberType NoteProperty `
        -Name Version -Value ($bios.version)    

    $obj | Add-Member -MemberType NoteProperty `
         -Name Manufacturer -Value ($bios.manufacturer)

    $obj | Add-Member -MemberType NoteProperty `
        -Name Status -Value ($bois.status)

    $obj | Add-Member -MemberType NoteProperty `
        -Name SerialNumber -Value ($bios.serialnumber)

    $obj | Add-Member -MemberType NoteProperty `
        -Name DiskSize -Value ($disk.size / 1GB -as [int])

    $obj | Add-Member -MemberType NoteProperty `
        -Name SysDriveFree -Value ($disk.freespace / 1GB -as [int])

    $obj | Add-Member -MemberType NoteProperty `
        -Name ComputerName -Value ($pc.model)

    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-Content C:\Users\Kev\Desktop\computers.txt| Get-CompInfo | ConvertTo-Html | Out-File C:\Users\kev\Desktop\Output.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top