微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PowerShell-展开组对象

如何解决PowerShell-展开组对象

我想扩展一个PowerShell组对象。 但是只有第一个对象。

Get-EventLog -Logname system -EntryType "Error" | group-object 'InstanceID' | Select-Object Count,Name,@{Name="Message";Expression={$_.Group.Message[0]}} | Format-Table -Wrap

结果:

Count Name Message                                                                                                                                                       
----- ---- -------                                                                                                                                                       
  161 17   ESIF(8.7.10200.12510) TYPE: ERROR MODULE: DPTF TIME 81546445 ms                                                                           

很好。但是,如果只有1个事件计数:

Count Name Message  
----- ---- ------- 
    1 8193 V    

他们只有第一个字符。

如何获取完整的第一个String? 有什么建议吗?

谢谢。

解决方法

您可以使用Select-Object选择第一条消息。

Get-EventLog -Logname system -EntryType "Error" |
    Group-Object 'InstanceID' | Select-Object Count,Name,@{Name="Message";Expression={$_.Group.Message | select -first 1}} |
            Format-Table -Wrap

对于我来说,示例输出与您的输出之间的唯一区别是,整个消息是针对单个计数条目而不是第一个字符收集的。

Count Name       Message                                                                                                                                                                      
----- ----       -------                                                                                                                                                                      
    8 15         The device driver for the Trusted Platform Module (TPM) encountered a non-recoverable error in the TPM hardware,which prevents TPM services (such as data encryption) from  
                 being used. For further help,please contact the computer manufacturer.                                                                                                      
                                                                                                                                                                 
    6 3221232481 A timeout was reached (30000 milliseconds) while waiting for the GameDVR and Broadcast User Service_15bc71 service to connect.                                               
                                                         
    3 20         Installation Failure: Windows failed to install the following update with error 0x80073d02: 9WZDNCRFJ364-MICROSOFT.SKYPEAPP.                                                 
    1 36871      A fatal error occurred while creating a TLS client credential. The internal error state is 10013.                                                                            
    2 10001      The description for Event ID '10001' in Source 'DCOM' cannot be found.  The local computer may not have the necessary registry information or message DLL files to display   
                                                                                                                                               
    1 3221232495 The Network List Service service terminated with the following error:                                                                                                        
                 %%21   

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?