get-winevent:将格式文件更改为groupbylogname无效



我想将get-winevent的默认输出更改为powershell 5.1中的样子,因此标头显示LogName而不是ProviderName。

get-winevent application -MaxEvents 1

LogName: Application
TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
8/23/2020 10:32:25 AM            0

我可以在powershell 7中很容易地做到这一点,方法是在$PSHOME:下编辑Event.format.ps1xml

<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 生成的类型和格式

有人确认,由于性能原因,powershell 5.1中未使用event.format.ps1xml。格式是在c#中定义的。https://github.com/PowerShell/PowerShell/issues/1218#issuecomment-678804787

"格式化表-按日志名分组;有点像ps5中的作品。标题仍然写着";providername";,但事实并非如此。最好先把它分类$pshome\event.format.ps1xml在powershell 5.1中没有函数。我认为EventLogRecord类型无法进行格式化。

get-winevent application,system -maxevents 3 | sort logname | ft -GroupBy logname

ProviderName: Application
TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
8/23/2020 7:10:04 PM         16384 Information      Successfully scheduled Software Protection service for re-start at 20...
8/23/2020 8:06:25 PM           455 Error            svchost (7476,R,98) TILEREPOSITORYS-1-5-18: Error -1023 (0xfffffc01) ...

ProviderName: System
TimeCreated                     Id LevelDisplayName Message
-----------                     -- ---------------- -------
8/23/2020 8:14:59 PM         10016 Warning          The machine-default permission settings do not grant Local Activation...

最新更新