Get-CimInstance CIM_Processor 返回多个“名称”
我正在尝试获取我域中所有计算机的 cpu 名称。我正在运行以下命令,
Get-CimInstance -ComputerName $i.DNSHostName -Class CIM_Processor | Select-Object "PSComputerName", "Name", "NumberOfCores"
我正在使用此结果来构建自定义对象
$workstationWithIp = [PSCustomObject]@{
ComputerName = $i.DNSHostName
CPU = $workstationObj.Name
Cores = $workstationObj.NumberOfCores
IP = $ip
Memory = $memory
Uptime = $uptimeHours
OS = $os.Caption + " " + $os.Version
}
我的问题是,某些机器有多个处理器,因此“名称”将返回多个结果。所有这些服务器都有多个相同的模型,那么我怎样才能得到结果,以便我可以将它作为字符串放入我的自定义对象中?我正在使用这些自定义对象来制作 CSV,其中一些将具有 cpu 名称和核心,但具有多个 cpu 的对象将为我提供 System.Object[] 作为 csv 中的名称和核心计数
I'm trying to get the cpu name for all of the machines on my domain. I'm running the following
Get-CimInstance -ComputerName $i.DNSHostName -Class CIM_Processor | Select-Object "PSComputerName", "Name", "NumberOfCores"
I'm taking the results of this to build a custom object
$workstationWithIp = [PSCustomObject]@{
ComputerName = $i.DNSHostName
CPU = $workstationObj.Name
Cores = $workstationObj.NumberOfCores
IP = $ip
Memory = $memory
Uptime = $uptimeHours
OS = $os.Caption + " " + $os.Version
}
My issue is that some of the machines have more than one processor so the "Name" will return multiple results. All of these servers have multiple of the same model so how can I get the result knocked down so I can put it into my custom object as a string? I'm using those custom objects to make a CSV and some will have the cpu name and the core fine but the ones with multiple cpus will give me System.Object[] for the name and core count in the csv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中提到的,从潜在的数组/值集合中选择最多 1 个项目的安全方法是通过管道传输到
Select-Object -First 1
:As mentioned in the comments, a safe way to pick at most 1 item from a potential array/collection of values is by piping to
Select-Object -First 1
: