请解释get-eventlog命令的Powershell输出 - 默认输出格式

3
get-eventlog -list

这是什么意思?请提供更多上下文信息。
 Max(K) Retain OverflowAction        Entries Log                                                                      
 ------ ------ --------------        ------- ---                                                                      
 20,480      0 OverwriteAsNeeded      14,418 Application                                                              
 20,480      0 OverwriteAsNeeded           0 HardwareEvents                                                           
    512      7 OverwriteOlder              0 Internet Explorer                                                        
 20,480      0 OverwriteAsNeeded           8 Key Management Service                                                   
    128      0 OverwriteAsNeeded          36 OAlerts                                                                  
                                          Security                                                                 
 20,480      0 OverwriteAsNeeded       8,771 System                                                                   
    512      7 OverwriteOlder              0 Windows Azure                                                            
 15,360      0 OverwriteAsNeeded          53 Windows PowerShell                                                       

并且...

get-eventlog -list | get-member

在这个结果中(为了简洁而截断):
TypeName: System.Diagnostics.EventLog

Name                      MemberType Definition                                                                        
----                      ---------- ----------                                                                        
Disposed                  Event      System.EventHandler       
Disposed(System.Object, System.EventArgs)                     
EntryWritten              Event      
System.Diagnostics.EntryWrittenEventHandler EntryWritten(System.Object, System....
BeginInit                 Method     void BeginInit(), void 
ISupportInitialize.BeginInit()                             
Clear                     Method     void Clear()                                                                      
Close                     Method     void Close()                                                                      
CreateObjRef              Method     System.Runtime.Remoting.ObjRef 
CreateObjRef(type requestedType)         

我的问题是:为什么get-eventlog -list会生成第一个结果集,但当将其传送到get-member时,却会产生第二个结果集?这两个结果似乎没有关联?还有...这些信息存储在哪里?我的意思是,我怎样才能自己找到答案呢?
谢谢。

1
它位于 types ps1xml 模块文件中,该文件控制将信息显示到控制台的方式。 - Maximilian Burszley
2个回答

3
在TheIncorrigible1已经给你的基础上,至于这个问题...
我的问题是:为什么get-eventlog -list会产生第一个结果集,而当它被管道传递到get-member时会产生第二个结果集?这两个结果似乎没有关系。
因为第一个结果集,你明确要求列出系统上的物理日志。当然,这是你可以处理的内容。
第二个结果集是你要求获取cmdlet的所有方法和属性。这是用来对这些日志采取行动的。Get-Member允许我们获取有关cmdlets返回的对象的信息。
完全记录在帮助文件和在线上。

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-member?view=powershell-6

这两者不是同一件事,因此输出结果不同。


3
PowerShell有自己的用于显示输出格式的系统,如格式文件概述Get-Help about_Format.ps1xml所述。它基于将格式规则与.NET类型关联,按视图类型进行分类:表格、列表、宽度、自定义。默认规则适用于没有关联格式数据的类型。
  • 使用隐式输出到控制台时,将使用在格式数据中定义的默认视图类型;如果没有,则具有最多4个属性的对象会导致表格显示(隐式Format-Table),超过这个范围,将使用每个对象多行列表显示(隐式Format-List)。
  • 或者,您可以使用Format-* cmdlet生成特定的输出格式:Format-Table(表格视图)、Format-List(列表视图)、Format-Wide(宽、单属性、多列视图)、Format-Custom(以类似JSON的格式通用显示对象的内部结构的视图)。
要查看与给定类型关联的格式规则,请使用Get-FormatData
在这种情况下,Get-EventLog输出类型为[System.Diagnostics.EventLog]的对象,因此要检查它们的格式数据,请使用:
Get-FormatData System.Diagnostics.EventLog | Format-Custom -Depth 10

理解输出结果并非易事,但所有格式信息都在其中。 格式信息的位置:
  • In Windows PowerShell, formatting information that ships with PowerShell can be found in *.Format.ps1xml files in the directory subtree of $PSHOME. To list them all, run:

    Get-ChildItem $PSHOME -Filter *.Format.ps1xml -Recurse
    
  • In PowerShell (Core) v6+, the formatting information that ships with PowerShell is compiled into the executable (pwsh).

  • Third-party modules may contain their own *.Format.ps1xml files to define formatting for the types they output, module-internally referenced via the FormatsToProcess entry in the module's manifest (*.psd1).


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接