最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powershell - How to pull the model name of a Lenovo ThinkCenter M75q Gen 2 - Stack Overflow

programmeradmin6浏览0评论

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.

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.

Share Improve this question asked Jan 17 at 15:04 Colored_RedColored_Red 333 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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

发布评论

评论列表(0)

  1. 暂无评论