Difference between revisions of "Finding the length of an array"
From MyWiki
(2 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
</source> | </source> | ||
Not sure about the above syntax.<br> | Not sure about the above syntax.<br> | ||
+ | Below the $roy.length gives no output but $dd.length gives a value of "1"<br> | ||
<source lang="powershell"> | <source lang="powershell"> | ||
+ | PS C:\scripts> $roy.length | ||
+ | PS C:\scripts> | ||
PS C:\scripts> $roy.samaccountname | PS C:\scripts> $roy.samaccountname | ||
abcde001 | abcde001 |
Latest revision as of 10:41, 1 April 2016
Using the ".length" will only correctly give the number of items in an array of there is more that one item.
If the item has one item this method will fail.
$a = ls *.bak|foreach {$_.name} # Replace above with below $a = @($a = ls *.bak|foreach {$_.name})
Not sure about the above syntax.
Below the $roy.length gives no output but $dd.length gives a value of "1"
PS C:\scripts> $roy.length PS C:\scripts> PS C:\scripts> $roy.samaccountname abcde001 PS C:\scripts> $dd = @( $roy.samaccountname) PS C:\scripts> $dd.length 1