本文介绍了WMI查询 - 多个处理器 - 寻找单个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, Hi all, 我正在开发一个powershell脚本来提取远程机器信息并将其转储到Excel工作表(用于资产管理/收集)。 道歉有一个冗长的解释,但这是我的思考过程。I'm working on a powershell script to pull remote machine information and dump it to an Excel worksheet (for asset management/collection). Apologies for a lengthy explanation, but this is my thought process.当我查询具有多核/多个cpus的机器时,我遇到的一个错误。A bug I've run into rears its head when I query a machine with multi-core / multiple-cpus.如果我这样做:[math]::Round(((Get-WmiObject win32_processor -ComputerName <computername>).MaxClockSpeed * .001),1)我收到错误"无法找到"Round"的过载和参数计数:"2"。I get an error "Cannot find an overload for "Round" and the argument count: "2".我已经确定(这可能有缺陷),这可能是因为查询结果我试图在一行上舍入产生2个单独的值:I've determined (this may be flawed) that this is likely because the query results I'm attempting to round on a single line produces 2 separate values: 2800 280028002800事实上,机器注册了2个CPU,CPU0和CPU1。请参阅以下结果 The machine in fact registers with 2 CPU's, CPU0 and CPU1. See below the results of Get-WmiObject win32_processor -ComputerName <computername> 标题 &NBSP; &NBSP; &NBSP; &NBSP; :x86 Family 15 Model 6 Stepping 5 DeviceID &NBSP; &NBSP; &NBSP; :CPU0 制造商 &NBSP; :GenuineIntel MaxClockSpeed &NBSP; :2800 名称 &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :Intel(R)Pentium(R)D CPU 2.80GHz SocketDesignation: LGA775 标题 &NBSP; &NBSP; &NBSP; &NBSP; :x86 Family 15 Model 6 Stepping 5 DeviceID &NBSP; &NBSP; &NBSP; :CPU1 制造商 &NBSP; :GenuineIntel MaxClockSpeed &NBSP; :2800 名称 &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :Intel(R)Pentium(R)D CPU 2.80GHz SocketDesignation: LGA775Caption : x86 Family 15 Model 6 Stepping 5DeviceID : CPU0Manufacturer : GenuineIntelMaxClockSpeed : 2800Name : Intel(R) Pentium(R) D CPU 2.80GHzSocketDesignation : LGA775Caption : x86 Family 15 Model 6 Stepping 5DeviceID : CPU1Manufacturer : GenuineIntelMaxClockSpeed : 2800Name : Intel(R) Pentium(R) D CPU 2.80GHzSocketDesignation : LGA775我试图通过流水线"Where-Object"来减少结果的数量。像这样(我不包括圆形声明,认为在尝试对它运行数学之前获得单个数字结果会更好。)I attempted to lessen the number of results with a pipelined "Where-Object" like this (I am not including the round statement, figuring that it'd be better to get a single numeric result before attempting to run the math against it).(Get-WmiObject win32_processor -ComputerName <computername>).MaxClockSpeed | Where-Object {$_.DeviceID -like 'CPU0'}不幸的是,当我运行它时,而不是从标识为DeviceID"CPU0"的处理器获取MaxClockSpeed结果我什么都没得到。Unfortunately, when I run this, instead of getting the MaxClockSpeed result from the processor identified as DeviceID "CPU0", I get nothing at all.我认为这可能是因为我在Where-Object语句中使用了错误的限定符(我试过-eq而不是-like),但是还没有能够超越这一点。I thought this might be because I'm using the wrong qualifier in the Where-Object statement (I tried -eq instead of -like), but haven't been able to get past this point.建议,帮助和指针总是*赞赏。Suggestions, help and pointers are *always* appreciated.谢谢, Ben推荐答案 我想我找到了解决办法。 我管道它并使用select-object指定使用第一个结果。I think I found my solution. I pipe it and use select-object specifying to use the first result.感谢您的观点! 如果您想出一个更优雅的解决方案,请随时回复。Thanks for the views! If you come up with a more elegant solution feel free to reply. Ben 这篇关于WMI查询 - 多个处理器 - 寻找单个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-26 06:54