PowerShell - развернуть Group-Object

Я хочу расширить объект группы 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    

У них есть только первый знак.

Как я могу получить полную первую строку? Какие-либо предложения?

Благодарю.

1 ответ

Решение

Вы могли бы использовать 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   
Другие вопросы по тегам