Powershell Get-CimInstance -ClassName Win32_PhysicalMemoryArray

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
Dead_EyesAsked:
Who is Participating?
 
Zephyr ICTCloud ArchitectCommented:
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...
0
 
Zephyr ICTCloud ArchitectCommented:
Maybe different Powershell versions?

You can find out the versions with this:

$PSVersionTable.PSVersion

Open in new window

0
 
Dead_EyesAuthor Commented:
Would be great if it was that but all 3 are running the exact same PS version :(
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
Zephyr ICTCloud ArchitectCommented:
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 :-)
0
 
Dead_EyesAuthor 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
0
 
Zephyr ICTCloud ArchitectCommented:
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
0
 
Dead_EyesAuthor 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
0
 
Dead_EyesAuthor 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
0
 
Dead_EyesAuthor 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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.