Powershell Get-CimInstance -ClassName Win32_PhysicalMemoryArray

Dead_Eyes
Dead_Eyes used Ask the Experts™
on
This is probably going to be an easy one for someone out there. I am learning PowerShell and writing a script to detect memory configurations on machines and failing at the first hurdle of how many memory slots does a machine have and how many are populated. At first the command "Get-CimInstance -ClassName Win32_PhysicalMemoryArray" was a blessing as the property BankLabel or devicelocator looked like a win however I have 2 machines with win8.1 and one machine with server 2012R2 on and on 1 8.1 machine the propertys devicelocator and banklabel don't exist but memorydevices does and on the other 2 (8.1&2012R2) memorydeices does not exist but devicelocator and banklabel do. In short WTF how can I have two different sets of properties from the same command on the same version of PS? Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Zephyr ICTCloud Architect

Commented:
Maybe different Powershell versions?

You can find out the versions with this:

$PSVersionTable.PSVersion

Open in new window

Author

Commented:
Would be great if it was that but all 3 are running the exact same PS version :(
Zephyr ICTCloud Architect

Commented:
Did you also look at available scripts like this one or this one ...

If these work (with maybe a slight adjustment here or there) you'll be set ... No need to reinvent the warm water :-)
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
Yeah I have been getting idea's from them and all get information from one of the properties so will fail in the same way. I am writing myself as its a lot better for learning and really even if I don't end up with a working script and just end up with the knowledge of why and how properties can change its still a win
Zephyr ICTCloud Architect

Commented:
Well ... Maybe you need to work in an if statement that checks the OS before running the actual command, that way you could use either this or that command ... That is, if it is indeed different on all W2K12R2 servers and W8.1 respectively

Author

Commented:
Its not though that's my point on 1 x 8.1 and 1 x 2012r2 machine its one set of properties and on another 8.1 machine its another set of properties even though all machines are running PS v4
Cloud Architect
Commented:
Maybe it's the hardware that's causing it? Different hardware, different ways of approaching it... That will be interesting if that's the case ... I'll try to dig a little deeper and test it on some systems here...

Author

Commented:
I can fully appreciate some manufacturers not filling in bits of information but to change the name of the property just seems so out of place. I was thinking maybe it's based on type of machine (laptop v desktop) but even if why change a property name as it's just going to cause chaos like this

Author

Commented:
Ok I feel like an idiot now I got so caught up in exploring the Get-CimInstance instead of my usual Get-WMIObject I only just realised I was calling a cim class on one machine and a win32 class on the other........ Feeling like such a dumbass atm (points awarded for me wasting everyone's time)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial