Link to home
Create AccountLog in
Avatar of Dead_Eyes
Dead_EyesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Format-Table Missing results

Hi fairly new to powershell but have run into a problem I hope is easy to solve
I am trying to get BIOS versions from machines and am running the following script
(Query.txt contains the following info:
Select * from win32_bios
Select * from Win32_Computersystem
and Clients.txt is a list of computers), I am running windows 7 x64 (and the clients) Powershell V3, clients V2
The Script:

$aryquery = Get-Content -path C:\Scripts\BIOSID\Query.txt
$computer = Get-Content -path C:\Scripts\BIOSID\Clients.txt
Foreach ($query in $aryQuery)
{
 Get-WmiObject -Query $query -computername $computer | Format-Table name, SMBIOSBIOSVersion, Model | Out-File -FilePath C:\BIOSID\Results.txt
}

When I run this script I get the following result
Name                                    SMBIOSBIOSVersion                      Model                                
----                                                 -----------------                             -----                                
Comp-01                                                                                                DG41RQ__  
Comp-02                                                                                                DG41RQ__  

The SMBIOSBIOSVersion information is blank!
But when I Run
Get-WmiObject -Computername comp-02 -Class win32_bios | Format-Table Name, SMBIOSBIOSVersion, Model | Out-File -FilePath C:\BIOSID\Results.txt
The Model Colum is blank!
What am I doing wrong and why is my data missing?
Avatar of SubSun
SubSun
Flag of India image

Try..

$computers = Get-Content -path C:\Scripts\BIOSID\Clients.txt
Foreach ($computer in $computers)
{
 Get-WmiObject Win32_Computersystem -computername $computer | `
 Format-Table name,@{n="SMBIOSBIOSVersion";e={(Get-WmiObject win32_bios -ComputerName $computer).SMBIOSBIOSVersion}},Model |
 Out-File -FilePath C:\BIOSID\Results.txt -Append
}

Open in new window

You can also save the result to a csv file if required..
Get-Content -path C:\Scripts\BIOSID\Clients.txt | % {
$computer = $_
 Get-WmiObject Win32_Computersystem -computername $computer | `
 Select name,@{n="SMBIOSBIOSVersion";e={(Get-WmiObject win32_bios -ComputerName $computer).SMBIOSBIOSVersion}},Model
} | Export-Csv C:\BIOSID\Results.csv -NoTypeInformation

Open in new window

Avatar of Dead_Eyes

ASKER

Thanks for that I will try it asap (looks like syntax way out of my league at the moment lol). Do you have any idea why my way did not work?
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer