Home > Back-end >  Powershell command get-wmiobject bios and computersystem in one command
Powershell command get-wmiobject bios and computersystem in one command

Time:08-01

i am currently trying to display a few informations with one powershell script So far i created a command which displays the AD-Hostname, the Serialnumber and the manufacturer.

I get the Computername from Get-ADComputer command and the serialnumber and manufacturer from Win32_Bios. ----->>>>

(Get-ADComputer -Filter *).Name -like 'MS0*' | Foreach-Object {Get-CimInstance Win32_Bios -ComputerName $_ -ErrorAction SilentlyContinue | Select-Object PSComputerName, SerialNumber, Manufacturer}

Current command output

^Hostname, Serialnumber, Manufacturer

Now my questions is, if it is possible to also include the PC-Model into this command which is stored in the win32_computersystem. If yes, how?

Would appreciate some advice :)

CodePudding user response:

Something like

(Get-ADComputer -Filter *).Name -like 'MS0*' | Foreach-Object {
    $info = Get-CimInstance Win32_Bios -ComputerName $_ -ErrorAction SilentlyContinue | Select-Object PSComputerName, SerialNumber, Manufacturer
    $info | Add-Member -MemberType NoteProperty -Name 'Model' -Value (Get-CimInstance Win32_ComputerSystem -ComputerName $_ -ErrorAction SilentlyContinue).Model
    $info  # output the combined object
}

you mean?

CodePudding user response:

You'll have to do two separate calls to Get-CimInstance, one to each class. At that point I'd suggest creating a new object to merge the values. Ex.

(Get-ADComputer -Filter *).Name -like 'MS0*' |
ForEach-Object {
    $bios = Get-CimInstance Win32_Bios -ComputerName $_ -ErrorAction SilentlyContinue
    $cs = Get-CimInstance Win32_ComputerSystem -ComputerName $_ -ErrorAction SilentlyContinue
    [PSCustomObject]@{
        ComputerName = $_
        Manufacturer = $cs.Manufacturer 
        Model        = $cs.Model
        SerialNumber = $bios.SerialNumber
    }
} | Select-Object ComputerName, SerialNumber, Manufacturer, Model

Note that I used Manufacturer from Win32_ComputerSystem. The other one is bios manufacturer, so that would often just say American Megatrends Inc.

  • Related