Difference between revisions of "Finding the length of an array"
From MyWiki
Line 6: | Line 6: | ||
# Replace above with below | # Replace above with below | ||
$a = @($a = ls *.bak|foreach {$_.name}) | $a = @($a = ls *.bak|foreach {$_.name}) | ||
+ | </source> | ||
+ | Not sure about the above syntax.<br> | ||
+ | <source lang="powershell"> | ||
+ | PS C:\scripts> $roy.samaccountname | ||
+ | abcde001 | ||
+ | PS C:\scripts> $dd = @( $roy.samaccountname) | ||
+ | PS C:\scripts> $dd.length | ||
+ | 1 | ||
+ | |||
</source> | </source> |
Revision as of 10:33, 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.
PS C:\scripts> $roy.samaccountname abcde001 PS C:\scripts> $dd = @( $roy.samaccountname) PS C:\scripts> $dd.length 1