0

I populated an array with some GUIDs. When I do $array.count I get 350, which is what I expected. When I print $array, though, I only get 118 results. Any ideas why this would happen? Populated with this script:

$flows = get-adminflow -environmentname $environmentname -verbose
$flowids = $null
$flowids = @()
foreach($Flow in $flows){$flowids += $flow.Internal.properties.workflowEntityId}
$flowids.count
$flowids
Steven
  • 6,817
  • 1
  • 14
  • 14
JuTrust
  • 11
  • 5
  • 4
    I'm assuming you mean `$flowids.count` and not `$array`. Are you sure there is only a single value in `.workflowEntityId`? Also, you can just assign the output directly to the variable: `$flowids = foreach ($flow in $flows) { $flow.Internal.properties.workflowEntityId }`. – Abraham Zinala Jun 22 '22 at 13:56
  • how are you counting the output, are you using `Measure-Object`? Or just looking/counting lines of output. – Steven Jun 22 '22 at 14:12
  • 4
    [Try to I avoid using the increase assignment operator (`+=`) to create a collection](https://stackoverflow.com/a/60708579/1701026) as it is exponentially expensive. Besides for this, your can simply use [member access enumeration](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_member-access_enumeration). Just: `$flowids = $flows.Internal.properties.workflowEntityId` – iRon Jun 22 '22 at 14:27
  • @iron I had heard you shouldn't use that but didn't really know what to do instead. Thank you! Someone on Reddit pointed out that my array may have null values, and that was indeed the problem. Thanks everyone! – JuTrust Jun 22 '22 at 16:02

0 Answers0