Monday, January 19, 2009

More on Arrays vs Scalars

In a post yesterday, I looked at telling the difference between a scalar and arrays. The difference matters when working with PowerShell – a scalar has properties and methods, while an array has members that have properties and methods. You can directly reach into a scalar, whereas you need to process array members (e.g. using ForEach). If you assign a variable to the output of a cmdlet, or a pipeline of cmdlets, you may end up with zero, one or more objects inside that variable. When you go to process that variable in your script/function, you need to know the differences.

In yesterday’s post I noted that with GPO objects, what you got back was a collection, even if the collection had only one object. A comment left on the blog made a great point: this is a feature of the particular object model (i.e. GPMC objects). It’s not a feature of COM as such.

And this just underlines my conclusion – there’s no easy way to tell what you have, without knowing the object and underlying object model.

Technorati Tags: ,,,

1 comment:

$hay@Israel said...

Arrays have methods and proprties too :-)