simple powershell coding - just need to edit the way it prints output

Job ID: 34109550

Budget: $10 – $30 AUD

got a powershell coding to get instance id's from aws console using some filters..

just have to sort the output a bit in proper way in few possibilities.



$instances=(Get-EC2Instance -Filter @{ Name="owner-id";Values=111111111}, @{ Name="tag:environment";Values="testing"}, @{ Name="tag:Component";Values="operations"}).Instances
$list="ServerName,instanceID"
forEach ( $ins in $instances ) {
$HostName=($ins.Tags|? {$_.Key -eq "ServerName"});
$instance_ID=$($ins.instanceId);
$list=$list+"$($HostName.Value),$instance_ID "
}
$list | Sort-Object | Select -First 1



below is the output it displays now:

ServerName,instanceID testingA,instance1T,testingB,instance2T,OperationsA,instance1O,OperationsB,instance2O


my question:
1- just need to sort my current output, currently it displays: 2*servers & its instanceID's from testing group and 2*servers & its instanceID's from operation group

from testing group = i want to arrange its output in ascending order and take out the first hostname separately and put in a varaiable
from operations group = i want to arrange its output in ascending order and take out the first hostname separately and put in an another varaiable

i have tried the Sort-Objet command which is the last line in my code, but it did not work to sort it
Related categories: C Programming Python Shell Script Powershell Aws Lambda