I am looking for a way to rank values in a csv column in powershell, similar to python in which you would read the column into list

Pass the csv column into a powershell list? Or use a powershell module? I am trying to count the frequency of IP addresses in a device log, thanks!

Your description is a bit vague. I assume you’ve heard about Import-Csv or haven’t you? If not - please read the complete help topic including the examples to learn how to use it

1 Like

As well Import-CSV, you might look at Group-Object.

Example, using ConvertFrom-Csv in lieu of Import-Csv:

$data = @'
IP,ComputerName
10.0.0.1,host1
10.0.0.2,host2
10.0.0.1,host3
10.0.0.1,host3
10.0.0.2,host4
10.0.0.3,host5
'@

$csv = $data | ConvertFrom-Csv
$csv | Group-Object IP

Output:

Count Name                      Group
----- ----                      -----
    3 10.0.0.1                  {@{IP=10.0.0.1; ComputerName=host1}, @{IP=10.0.0.1; ComputerName=host3}, @{IP=10.0.0.1; ComputerName=host3}}
    2 10.0.0.2                  {@{IP=10.0.0.2; ComputerName=host2}, @{IP=10.0.0.2; ComputerName=host4}}
    1 10.0.0.3                  {@{IP=10.0.0.3; ComputerName=host5}}
1 Like