• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1484
  • Last Modified:

Powershell. Find the number of columns in an array.

Powershell v1.
I'm writing a script that puts the contents of an array into an Excel workbook. The scripts needs to know how many columns and how many rows are in the array. The count property gives me the number of rows. How do I find out the number of columns in an aray?

Consider the following snippet:
$array=@("Row1,Col1","Row1,Col2","Row1,Col3","Row1,Col4","Row1,Col5"),("Row2,Col1","Row2,Col2","Row2,Col3","Row2,Col4","Row2,Col5")

If you type "$array.length", you get response "2" because there are 2 rows in the array. But suppose you want to know how many columns are in the array. You can see that there are are 5 columns. How do you programmatically get that number?
0
HondoExpat
Asked:
HondoExpat
1 Solution
 
elimesikaCommented:
HI

Try this

The reason is that you have an array that has two nested arrays...
$array[0].length
$array[1].length

Open in new window

0
 
HondoExpatAuthor Commented:
That works perfectly. Sometimes I wish PS was a little more intuitive.
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now