How can I put $org into an array together with $count?
Like this example array:
$myArray = @{
1="SampleOrg";
2="AnotherSampleOrg"
}
Another example:
$myArray = @{
$count="$org";
$count="$org"
}
Example foreach:
$count=0;get-organization | foreach {$count++; $org = $_.Name.ToString();write-host $count -nonewline;write-host " $org"}
$answer = read-host "Select 1-$count"
The above will display:
1 SampleOrg
2 AnotherSampleOrg
Select 1-2:
What I would like to do afterwards is to put the array to use in a switch.
Example:
switch ($answer)
{
1 {$org=myArray[1]} #<-- or whatever that corresponds to "SampleOrg"
2 {$org=myArray[2]} #<-- or whatever that corresponds to "AnotherSampleOrg"
}
$myArray.Add($count, $org)to yourforeach-loop. EDIT: And you have to initialize your array somewhere before the loop:$myArray = @{}$myArray = @{};$count=0;get-organization | foreach {$count++; $org = $_.Name.ToString();write-host $count -nonewline;write-host " $org";$myArray.Add($count, $org)}