I have a (soon to be) advanced function that I am writing to gather some system information from various machines in our environment (name, os, service tag, disk, ram, etc).
I am getting all of the data back that I want to get, it just isn’t displaying the way that I am expecting. Here is part of my code…
foreach($c in $ComputerName) { Get-WmiObject -Class Win32_LogicalDisk -ComputerName $c -Credential $Credential -Filter "DriveType=3" -OutVariable disk | Out-Null Get-WmiObject -ComputerName $c -Class Win32_BIOS -Credential $Credential | Select -ExpandProperty SerialNumber -OutVariable serviceTag | out-null Get-WmiObject -Class Win32_OperatingSystem -ComputerName $c -Credential $Credential | Select -Property Caption,CDSVersion,OSArchitecture,LastBootUpTime -OutVariable os | Out-Null Get-WmiObject -Class Win32_ComputerSystem -ComputerName $c -Credential $Credential | Select -Property Caption, Manufacturer, Model, NumberOfProcessors,TotalPhysicalMemory -OutVariable sys | Out-Null [int]$amountOfDisk = 0 foreach($d in $disk) { $amountOfDisk += $d.size / 1gb -as [int] } $prop = [ordered]@{ 'ComputerName' = $c 'Manufacturer'= $sys.manufacturer 'Model'= $sys.model 'ServiceTag' = $serviceTag 'OS' = $os.caption 'Architecture' = $os.OSArchitecture 'Processors'= $sys.NumberOfProcessors 'Memory (GB)'= $sys.TotalPhysicalMemory / 1gb -as [int] 'Disk (GB)' = $amountOfDisk#> } $obj = New-Object -TypeName PSObject -Property $prop write-output $obj | Format-Table -AutoSize }
I don’t know why I am getting headings for each object returned… whether the -Autosize switch is put on the Format-Table or not. I have attached an image to explain.
Any help or explanation would be greatly appreciated.
Thanks
sb