Converting VBScript's IsArray Function
Definition: Returns a Boolean value indicating whether a variable is an array.
When it comes to working with arrays, Windows PowerShell is a bit more forgiving than VBScript. For example, VBScript will blow up with a “Type mismatch” error should you try to directly echo the value of an array; instead, you need to set up a For Each loop to get at those values (or specify individual values one at a time). With Windows PowerShell you don’t have to worry about that; a simple command such as this will echo back all the values in the array $a, no For Each loop required:
That said, there will still be times when you’ll find it useful to know, in advance, whether or not you are dealing with an array. In Windows PowerShell that can be done by using the -is operator and then checking to see if the item has an array data type. In these two lines of code, we create an array named $a, then check to see whether or not we really do have an array. The return value (True or False) is then stored in the variable $b:
$a = 22,5,10,8,12,9,80 $b = $a -is [array]
When you run this command and then echo back the value of $b you should get the following: