For my current project at the office I needed to had some logs into a script with runspace that will run over at least 15 000 (15k, fifteen thousands, ….) PowerShell Objects.
And as all knows, all good log need to store the DateTime when the event append.
Before today I was using the, basic but efficient:
[ps]Get-Date -Format ‘dd/MM/yyyy hh:mm:ss'[/ps]
Then, I started wondering why do not use the .NET Class, because I had a chat with some co-workers and did some digging over Internet.
So I tried fifteen thousands times both commands, and here is the result of the Measure-Command:
The result show us that the .Net Class DateTime is nearly 10 times faster than the wraper PowerShell Cmdlet when it comes to 15k PowerShell Objects.
As of today I will make more use of the .Net Class [DateTime] directly instead of the Get-Date wraper.
To match the Log requirement that I get for the current project I used the following command to replace the “Get-Date -Format” that I was using previously: