powershellsystem-information

How to pull the model name of a Lenovo ThinkCenter M75q Gen 2


I'm on Powershell v 5.1.19041.1682.

I have a script that will pull basic system information that sets them as variables and outputs it to a .txt file. Up until now my company has used HP mini PCs, which I can use the following to obtain the system model so I can set it as a variable:

(Get-WmiObject -Class Win32_ComputerSystem). Model

That result is the model, such as "HP EliteDesk 600 G9" for example.

However, we are now switching to Lenovo PCs and the same string pulls "11JQS8EJ0A" instead of "ThinkCenter M75q Gen 2". If I use Get-ComputerInfo command the model shows up how I'd like it to under "CsSystemFamily", but I'm at a loss of how to pull the exact model name separately so I can set it as a variable.

Calling me an amateur would be a compliment. I'm winging it, so I apologize if this is a Powershell 101 question.


Solution

  • First, do notuse WMI cmdlets: they have been obsolete since Powershell 3 and have been removed from Powershell 6+.

    Use CIM cmdlets instead: it will make your code forward-compatible(and still backward compatible down to Powershell 3)

    Get-CimInstance -ClassName Win32_ComputerSystem will return the same values as your WMI cmdlet.

    Also, you do not need to call Get-ComputerInfo: its CsSystemFamily property is derived from the SystemFamily property of Get-CimInstance -ClassName Win32_ComputerSystem!
    (Get-ComputerInfo basically just calls multiple Get-CimInstance and compiles them together, to simplify it to an extreme degree)

    So you can simply use
    $VariableNameYouDecide = (Get-CimInstance -ClassName Win32_ComputerSystem).SystemFamily

    Also: using Get-CimInstance -ClassName Win32_ComputerSystem | Format-List -Property * you can look at all the properties not just those automatically shown