如何在PowerShell 5.1中获取联想ThinkCenter M75q Gen 2的型号名称
PowerShell提取电脑型号的解决方案
单独提取CsSystemFamily字段
直接通过点标记法访问Get-ComputerInfo返回对象的CsSystemFamily属性即可:
# 将正确型号存入变量 $computerModel = (Get-ComputerInfo).CsSystemFamily # 输出到txt文件,可自行修改路径 $computerModel | Out-File -FilePath "C:\你的路径\电脑型号.txt" -Encoding UTF8
兼容多品牌的通用脚本
不同品牌电脑的有效型号字段可能存在差异(比如惠普用Win32_ComputerSystem.Model,联想用CsSystemFamily),可以写个兼容逻辑适配不同机器:
# 优先尝试Get-ComputerInfo的CsSystemFamily $model = (Get-ComputerInfo).CsSystemFamily # 如果该字段为空(比如惠普机器),则回退到Win32_ComputerSystem的Model if (-not $model) { $model = (Get-WmiObject -Class Win32_ComputerSystem).Model } # 将结果输出到文件,路径按需修改 $model | Out-File -FilePath "C:\SystemInfo\ComputerModel.txt" -Encoding UTF8
内容的提问来源于stack exchange,提问作者Colored_Red
相关产品推荐
相关产品推荐

