我想在 powershell 5.1 中将 get-winevent 的默认输出更改为如下所示,因此标题显示的是 LogName 而不是 ProviderName。
get-winevent application -MaxEvents 1
LogName: Application
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
8/23/2020 10:32:25 AM 0
通过在 $PSHOME 下的某处编辑 Event.format.ps1xml,我可以在 powershell 7 中非常轻松地做到这一点:
<ViewSelectedBy>
<TypeName>System.Diagnostics.Eventing.Reader.EventLogRecord</TypeName>
</ViewSelectedBy>
<GroupBy>
<PropertyName>LogName</PropertyName>
<Label>LogName</Label>
</GroupBy>
但是在powershell 5.1中,在更改了所有权和安全性以便我可以写入该文件之后,同样的更改似乎没有效果!似乎 get-winevent 完全忽略了该文件。我怎样才能做出这种改变?
cd $pshome
takeown /f Event.Format.ps1xml /a
icacls event.format.ps1xml /grant administrators:w
我认为这种格式是在 c# 的某个地方定义的? 删除为 Microsoft.PowerShell.Diagnostics #1218 生成的类型和格式