Powershell sort-object,csv

我有两个* .csv文件。 第一个包含这个

IP, MAC, Name, Comment 10.10.122.1, 66-55-44-33-22-11, testuser1, this is testuser 1 10.10.122.100, 66-55-44-33-22-12, testuser2, this is testuser 2 10.10.122.2, 66-55-44-33-22-13, testuser3, this is testuser 3 10.10.122.4, 66-55-44-33-22-14, testuser4, this is testuser 4 10.10.122.203, 66-55-44-33-22-15, testuser5, this is testuser 5 

第二个包含IP的sorting列表。 这是有点棘手的,因为你必须添加前导零sorting的IP,然后你需要删除前导零。 所以这个文件看起来像这样:

 10.10.122.1 10.10.122.2 10.10.122.4 10.10.122.100 10.10.122.203 

我怎么能得到其他的属性,例如像在第二个CSV文件中的IP适合的MACS?

我试图使用的对象,但不幸的是我不知道如何比较IP,然后链接正确的IP其他属性。

只需要对原始的csv进行sorting:

 $data = Import-Csv first.csv $data = $data | Sort-Object {"{0:000}.{1:000}.{2:000}.{3:000}" -f @([int[]]$_.IP.split("."))} 

现在,由于我们在sorting过程中将IP的每个八位字节都视为零填充string,因此它们将以正确的顺序列出。