开发者

WMI query issue in PowerShell

开发者 https://www.devze.com 2022-12-16 08:22 出处:网络
Here is where I have started: #Get Physical Memory function getwmiinfo ($svr) { gwmi -query \"select 开发者_如何学C* from

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
0

精彩评论

暂无评论...
验证码 换一张
取 消