Today we are doing 2 things, or actually 3 things:
Main reasons for doing this:
I can work around the bug in Get-WinEvent by temporarily switching to the culture en-us. When I have used Get-WinEvent and processed the results, I reset the culture to the original state. No harm done.
A few words about the custom object function (Create-CustomObject). It takes 2 parameters; Properties ([string[]]) and DefaultDisplayProps([string[]]). At the end it spits out a new object (PSobject) with the DefaultDisplayPropertySet’ configured. To demonstrate:
Okay, so the other properties can be displayed with:
Pretty cool, however I cheated a bit. I supplied 5 properties, however only 4 is displayed. Default is table view if you have 4 properties or less, so I removed the zip-property. If you use the format-table command, you can still override it like I have shown in the last picture. Here it is again with all 5 properties:
Here is the full code:
- Building a custom Get-EvntLog function built upon the standard Get-WinEvent cmdlet
- Using DefaultDisplayProperties
- Using an embedded function in an function (why, because why not, we can?)
Main reasons for doing this:
- Bug in .net and/or Get-WinEvent for any other culture than en-us (I use no-nb), The message property is returned as $null if I use Get-WinEvent
- Speed – Get-Eventlog is fine, however I want speed like we get with Get-WinEvent
I can work around the bug in Get-WinEvent by temporarily switching to the culture en-us. When I have used Get-WinEvent and processed the results, I reset the culture to the original state. No harm done.
A few words about the custom object function (Create-CustomObject). It takes 2 parameters; Properties ([string[]]) and DefaultDisplayProps([string[]]). At the end it spits out a new object (PSobject) with the DefaultDisplayPropertySet’ configured. To demonstrate:
Okay, so the other properties can be displayed with:
Pretty cool, however I cheated a bit. I supplied 5 properties, however only 4 is displayed. Default is table view if you have 4 properties or less, so I removed the zip-property. If you use the format-table command, you can still override it like I have shown in the last picture. Here it is again with all 5 properties:
Here is the full code:
Comments
Post a Comment