PowerShell 中的 WMI 查询问题
这是我开始的地方:
#Get Physical Memory
function getwmiinfo ($svr) {
gwmi -query "select * from
Win32_PhysicalMemory" -computername $svr | select [$svr], DeviceLocator
}
$Servers = get-content -path "C:\test.txt"
foreach($Servers in $Servers) {
getwmiinfo $Servers
}
我明白了:
[risk] DeviceLocator
------ -------------
DIMM0
DIMM1
我想要的是:
ServerName DeviceLocator
---------- -------------
RISK DIMM0
RISK DIMM1
这可能吗?我该怎么做呢。我已经花了几个小时在这上面,但无法完全让它发挥作用。谢谢!
Here is where I have started:
#Get Physical Memory
function getwmiinfo ($svr) {
gwmi -query "select * from
Win32_PhysicalMemory" -computername $svr | select [$svr], DeviceLocator
}
$Servers = get-content -path "C:\test.txt"
foreach($Servers in $Servers) {
getwmiinfo $Servers
}
I get this:
[risk] DeviceLocator
------ -------------
DIMM0
DIMM1
What I want is this:
ServerName DeviceLocator
---------- -------------
RISK DIMM0
RISK DIMM1
Is this possible? How would I do it. I have spent hours on this and can't quite get it to work. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
[$svr]
替换为ServerName
,因为[$svr]
不是您可以选择的字段。另外,我将更改为
注意 foreach 语句中的变量名称更改
更新
replace
[$svr]
withServerName
, because[$svr]
isn't a field you can select.Also, I'd change
to
Notice the variable name change in the foreach statement
Update