使用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. svn 同步hook

    hook 目录下 cp pre-revprop-change.tmpl pre-revprop-change chmod a+x pre-revprop-change 同步代码初始化 sudo svn ...

  2. 基于XML的AOP配置(2)-环绕通知

    配置方式: <aop:config> <aop:pointcut expression="execution(* com.itheima.service.impl.*.*( ...

  3. import 和 require 的 区别

    node编程中最重要的思想就是模块化,import和require都是被模块化所使用. 遵循规范 require 是 AMD规范引入方式 import是es6的一个语法标准,如果要兼容浏览器的话必须转 ...

  4. httpClient模仿Basic Auth

    httpclient代码调用如下: @GetMapping("loginTest") public String httpClientWithBasicAuth() { Strin ...

  5. Delphi组件编辑器

    看到Dev中的cxGrid组件的编辑器很强大,于是很想探究一下,跟踪cxGrid的代码比较麻烦,但原理大概知道一二.首先来研究一下设计器双击cxGrid弹出一个编辑窗体,选择窗体中的一个内容后,属性编 ...

  6. Oracle11g安装出现时未能满足某些最低安装要求

    需要开启C盘共享,才能检测硬件是否满足要求.cmd命令:net share c$=c::或者勾选全部忽略,继续下一步安装. 可参考https://blog.csdn.net/huazicomeon/a ...

  7. iOS限制输入解决方法

    关于iOS 键盘输入限制(只能输入字母,数字,禁止输入特殊符号): 方法一: 直接限制输入 - (void)viewDidLoad { [super viewDidLoad]; textField = ...

  8. 非线性函数图像表示(GLSL)

    说明:绘图区域x轴(0->1),y轴(0->1); 1.y = 0.5 + sqrt(x * (1 - x)) 2.y = smoothstep(a , b , x) y = smooth ...

  9. python 脚本带参数

    如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢? 需要模块:sys参数个数:len(sys.argv)脚本名:    sys.argv[0]参数 ...

  10. monkey详解

    Monkey是Android系统自带的一个命令行工具,用户主要是通过adb命令来启动Monkey,Monkey在运行时,会根据命令行参数的配置,生成伪随机事件流,并在Android设备上执行对应的测试 ...