Hi everyone, I have a gap in my knowledge i am hoping someone can fill, here is my problem:
I wish to dynamically query some info at runtime to then create a dynamic number of variables, which i then want to query also, the code i have is below:
`
`
The error is on this line $(“Node$i`Disksize”) = $TempSize, it cannot assign the value in $TempSize to the variable, what is the correct way to do this?
Regards
Wayne
yes this looks like my problem, the $item.value.size variable doesnt have an op method. However i need to get all of those disk sizes and store them in a variable, still working on it, i will post back as soon as i find anything
Personally, I’d say any time you’re trying to dynamically create variable names like this, what you really want is a collection of some sort. Maybe an array, maybe a dictionary, whatever makes more sense at the time. For example:
Incidentally, every single $i in that hashtable should wind up with identical data. You’re looping over the $AllNodes array, but not using $Node anywhere inside the loop (such as in the call to Get-PhysicalDisks.)
Interesting Dave, il look at the array / dictionary method thanks, and I wouldn’t examine the code too carefully, it was changed to protect its identity lol, it was more the logic i was trying to understand
Then the hashtable, $NodeSizes, will have the node name and total disk size as key-value pairs.
I see that the size of the PhysicalDisk object is an uint64. Measure-Object converts this and gives the sum as a double. You probably don’t need to worry about this, but keep the type in mind if you want to pass the value on