WMI query issue in PowerShell
Here is where I have started:
#Get Physical Memory
function getwmiinfo ($svr) {
gwmi -query "select 开发者_如何学C* 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!
replace [$svr]
with ServerName
, because [$svr]
isn't a field you can select.
Also, I'd change
foreach($Servers in $Servers) {
getwmiinfo $Servers
}
to
foreach($Server in $Servers) {
getwmiinfo $Server
}
Notice the variable name change in the foreach statement
Update
gwmi -query "select * from Win32_PhysicalMemory" | select __SERVER, DeviceLocator
精彩评论