如何对输出进行排序,每个 IP 地址在 PowerShell 中都有最大值?

How can I sort output, whre each ip-address have a maximum value in PowerShell?

) 我有一个代码:

$destination = @(Get-Content -Path "C:\Users\Juke\Documents\destination.txt");
$length = @(Get-Content -Path "C:\Users\Juke\Documents\length.txt");

function GetTable{
    $i = 0;
    echo ("Make a list IP = Pachet length");

    echo ($destination[1] + "  = " + $length[1]);
    for ($i = 1; $i -le 200; $i++){
        echo ($destination[$i+1] + "  =  " + $length[$i+1]);
    };

};
$res = GetTable;
$res;

这是输出:

95.100.190.60  = 54
95.100.190.60  =  1870
95.100.190.60  =  54
95.100.190.60  =  1869
95.100.190.60  =  54
95.100.190.60  =  1892
95.100.190.60  =  85
95.100.190.60  =  54
95.100.190.60  =  847
95.100.190.60  =  109
95.100.190.60  =  89
87.240.185.160  =  55
87.240.185.159  =  55
87.240.185.158  =  55
87.240.185.157  =  55
87.240.185.153  =  55
87.240.185.150  =  55
87.240.185.150  =  55
87.240.185.145  =  55
87.240.185.144  =  55
87.240.185.143  =  55
87.240.185.142  =  55
87.240.185.139  =  55
87.240.185.139  =  55
87.240.185.138  =  55
87.236.16.99  =  54
87.236.16.99  =  54
87.236.16.99  =  54
87.236.16.99  =  54
87.236.16.99  =  54

我必须找到每个 IP 地址的最大值。如您所见,Ip-addresses 在输出中重复出现。我做了一个 table ,其中每个 ip 都有值。结果应该是这样的:IP = 最大值。 我该怎么做?

而不是使用 echo 命令(它是 Write-Host), just drop a [pscustomobject] on the pipeline 的别名,易于排序:

function GetTable{
    $i = 0
    Write-Host "Make a list IP = Pachet length"

    [pscustomobject]@{ IP = $destination[$i]; Length = $length[$i] }
    for ($i = 1; $i -le 200; $i++){
        [pscustomobject]@{ IP = $destination[$i+1]; Length = $length[$i+1] }
    }
}

GetTable | Sort Length
**笔记**
  1. Do not use parenthesis around function arguments.
  2. 许多编程和脚本语言需要在 每行的结尾。虽然它们可以在 PowerShell 中以这种方式使用, 不推荐,因为不需要。