【问题标题】:Powershell Group Paramter - Count over 100 adds value to variablePowershell 组参数 - 计数超过 100 为变量增加值
【发布时间】:2017-06-05 02:49:13
【问题描述】:

我发现下面的文章可以帮助我对 IP 地址列表进行分组。

Using Powershell, how can i count the occurrence of each element in an array?

我目前使用的命令是:

get-content c:\temp\temp3.txt | group

这将得到以下输出:

> Count Name                      Group
----- ----                      -----
    3 192.168.1.1             {192.168.1.1, 192.168.1.1, 192.168.1.1}
    3 192.168.1.2             {192.168.1.2, 192.168.1.2, 192.168.1.2}

我可以使用什么命令来查找所有超过 5 个 IP 的 IP?

我想我需要将我的原始命令作为如下变量:

$groupedoutput get-content c:\temp\temp3.txt | group

不确定从那里去哪里。任何帮助将不胜感激。

谢谢,

S

【问题讨论】:

    标签: powershell output


    【解决方案1】:

    全文:

    Get-Content -Path c:\temp\temp3.txt  | 
        Group-Object  -NoElement         | 
        Where-Object  { $_.Count -gt 5 } | 
        Select-Object -ExpandProperty Name
    

    简而言之:

    gc c:\temp\temp3.txt | group |? count -gt 5 |% Name
    

    -NoElement 开关意味着组不会收集所有这些东西:{192.168.1.1, 192.168.1.1, 192.168.1.1},这里并不是必须的,但如果您不打算使用分组项,它可以节省内存。

    【讨论】:

    • 干得好,我更喜欢“选择名称”(我认为我也使用 SQL)
    猜你喜欢
    • 2019-11-16
    • 2018-04-24
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 2023-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多