使用Group-Object(group)按组统计

 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | group Noun

Count Name Group
----- ---- -----
3 LocalGroupMember {Add-LocalGroupMember, Get-LocalGroupMember, Remove-LocalGroupMember}
7 LocalUser {Disable-LocalUser, Enable-LocalUser, Get-LocalUser, New-LocalUser, Remove-LocalUser, Rename-LocalUser, Set-LocalUser}
5 LocalGroup {Get-LocalGroup, New-LocalGroup, Remove-LocalGroup, Rename-LocalGroup, Set-LocalGroup}

对统计的结果进行排序,注意:以下两个语句是等效的

 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | sort Noun | group Noun

Count Name Group
----- ---- -----
5 LocalGroup {Get-LocalGroup, New-LocalGroup, Remove-LocalGroup, Rename-LocalGroup, Set-LocalGroup}
3 LocalGroupMember {Add-LocalGroupMember, Get-LocalGroupMember, Remove-LocalGroupMember}
7 LocalUser {Disable-LocalUser, Enable-LocalUser, Get-LocalUser, New-LocalUser, Remove-LocalUser, Rename-LocalUser, Set-LocalUser} PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | group Noun | sort Name

Count Name Group
----- ---- -----
5 LocalGroup {Get-LocalGroup, New-LocalGroup, Remove-LocalGroup, Rename-LocalGroup, Set-LocalGroup}
3 LocalGroupMember {Add-LocalGroupMember, Get-LocalGroupMember, Remove-LocalGroupMember}
7 LocalUser {Disable-LocalUser, Enable-LocalUser, Get-LocalUser, New-LocalUser, Remove-LocalUser, Rename-LocalUser, Set-LocalUser}

在Format-Table里使用-GroupBy按组显示结果,必须先对Groupby的字段进行排序,否则Groupby的字段不会显示在一起

 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | sort Noun | ft -GroupBy Noun
Noun: LocalGroup CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts Noun: LocalGroupMember CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts Noun: LocalUser CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Disable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Enable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts

Format-Table处理以后,一般不能再进行"|"操作,否则会出错

 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | ft -AutoSize

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Disable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Enable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | ft -AutoSize | sort Name

out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" is not valid or not in the
correct sequence. This is likely caused by a user-specified "format-*" command which is conflicting with the default formatting
.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

有时候虽然能执行,但结果也和预期不符

 PS C:\> Get-Command -Module Microsoft.PowerShell.LocalAccounts | ft -AutoSize | group Noun

Count Name Group
----- ---- -----
19 {Microsoft.PowerShell.Commands.Internal.Format.FormatStartData, Microsoft.PowerShell.Command... PS C:\> $data = Get-Command -Module Microsoft.PowerShell.LocalAccounts | ft -AutoSize | group Noun

PS C:\> $data.Group

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Add-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Disable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Enable-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Get-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet New-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalGroupMember 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Remove-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Rename-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalGroup 1.0.0.0 Microsoft.PowerShell.LocalAccounts
Cmdlet Set-LocalUser 1.0.0.0 Microsoft.PowerShell.LocalAccounts

最后,Group-Object(group)这个cmdlet在Microsoft.PowerShell.Utility这个Module里,不在Microsoft.PowerShell.Core里

 PS C:\> Get-Command *-Object* | sort Source | ft -AutoSize

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet ForEach-Object 3.0.0.0 Microsoft.PowerShell.Core
Cmdlet Where-Object 3.0.0.0 Microsoft.PowerShell.Core
Cmdlet Compare-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Group-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Measure-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet New-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Register-ObjectEvent 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Select-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Sort-Object 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Tee-Object 3.1.0.0 Microsoft.PowerShell.Utility PS C:\> Alias | where DisplayName -like "*Object*" | select Definition, Name | sort Definition

Definition Name
---------- ----
Compare-Object compare
Compare-Object diff
ForEach-Object %
ForEach-Object foreach
Get-WmiObject gwmi
Group-Object group
Measure-Object measure
Remove-WMIObject rwmi
Select-Object select
Sort-Object sort
Tee-Object tee
Where-Object ?
Where-Object where

在Powershell中使用Group-Object和-GroupBy的更多相关文章

  1. 使用管道符在PowerShell中进行各种数据操作

    最近在培训PowerShell,在讲到Pipeline的时候,对于我这种长期和数据(数据库)打交道的人来说,觉得很实用,所以写此博文,记录一下. 无论是在Linux中写Bash脚本还是在Window上 ...

  2. powershell中使用超大内存对象

    powershell中使用超大内存对象 简单介绍了powershell中超大内存对象的用途,开启powershell超大内存对象的办法. powershell 传教士 原创文章 2016-12-31 ...

  3. buffer cache中,各个object对象占用的buffer blocks

    buffer cache中,各个object对象占用的buffer blocks: COLUMN OBJECT_NAME FORMAT A40 COLUMN NUMBER_OF_BLOCKS FORM ...

  4. PowerShell中的基础数据类型

    PowerShell是一个面向对象的语言,在申明变量的时候不强制要求申明数据类型,使用$开头来申明变量即可. 基本数据类型 PowerShell本身是基于.Net开发出来的,所以在.Net中的基本数据 ...

  5. 【前端】js中new和Object.create()的区别

    js中new和Object.create()的区别 var Parent = function (id) { this.id = id this.classname = 'Parent' } Pare ...

  6. 【python】正则中的group()

    来源:http://www.cnblogs.com/kaituorensheng/archive/2012/08/20/2648209.html 正则表达式中,group()用来提出分组截获的字符串, ...

  7. powershell中的两只爬虫

    --------------------序-------------------- (PowerShell中的)两只爬虫,两只爬虫,跑地快,爬网页不赖~~~ 一只基于com版的ie,一只基于.net中 ...

  8. 在本地主机上powershell中连接远程主机执行vbs脚本,得到执行结果(2008版及以上)

    在桌面版的主机上远程管理服务器版主机,在本地powershell中连接远程主机执行vbs脚本,得到执行结果. 执行步骤: 1.将本地主机上的Hyper.vbs复制到远程连接主机上.例如,本地vbs脚本 ...

  9. Linq中join & group join & left join 的用法

    Linq中join & group join & left join 的用法 2013-01-30 11:12 12154人阅读 评论(0) 收藏 举报  分类: C#(14)  文章 ...

  10. PowerShell_零基础自学课程_5_自定义PowerShell环境及Powershell中的基本概念

    PowerShell_零基础自学课程_5_自定义PowerShell环境及Powershell中的基本概念 据我个人所知,windows下的cmd shell除了能够通过修改系统参数来对其中的环境变量 ...

随机推荐

  1. (六)C语言之隐式转换

  2. 一、Git的一些命令操作----创建版本库、增加文件到Git库、时光机穿梭、远程仓库

    具体详细教程请链接:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 我这里只是记录 ...

  3. PHPstrom中关闭提示信息

    设置里面搜索parameter name hints

  4. github搜索不到代码的问题

    Hi team, Please check the following three query url :https://github.com/Konctantin/GreyMagic/search? ...

  5. oracle性能诊断sql

    --1.阻塞及等待事件信息查询-- 查询所有会话的状态.等待类型及当前正在执行的SQL脚本select t.SID, t.SERIAL#, t.Status, t.Action, t.Event, t ...

  6. 在WPF中使用AForge控件

    AForge.NET 是用C#写的一个关于计算机视觉和人工智能领域的框架,它包括图像处理.神经网络.遗传算法和机器学习等. 要实现视频功能,需要使用AForge.Controls命名空间中的Video ...

  7. C#汉字转换拼音技术详解(高性能)

    public static class ChineseToPinYin { private static readonly Dictionary<<span class="key ...

  8. LC 962. Maximum Width Ramp

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  9. 阶段3 3.SpringMVC·_03.SpringMVC常用注解_6 CookieValue注解

    演示 访问服务器会有session.它是一cookie的形式返回给客户端的 拿到的值

  10. docker 入门 命令

    docker 命令 docker images 镜像列表 docker ps 服务列表 docker 隐藏打包文件 .dockerignore .git node_modules npm-debug. ...