The output of the above is what I want but the log file has the date all weird in the format
Mon Aug 1 20:30:50 2022
I am trying to figure out how to take the above output and format it like below
Mon Aug 1 2022 20:30:50
I have been trying to search google for everything i can think might work and none of it seems to get me where I want to be…So I am here hoping someone has for more knowledge than me on this.
The other option would be to parse the string to a [DateTime] type. Then you can format to any of the available options for this type. Depending on your actual language setting you may adjust the language code in this snippet.
[datetime]::ParseExact('Mon Aug 1 20:30:50 2022','ddd MMM d HH:mm:ss yyyy',[Globalization.CultureInfo]::CreateSpecificCulture('en-us'))
BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thank you for the response, sorry about the incorrect format…Last time I was here it was backticks. The button will make things a lot easier.
You are a genius the first option works perfectly. Now the format is closer to the rest of the data collected and i can improve a few other options I have created in the past. Thank you for educating me.
It still is - but that’s more for single cmdlets names or parameters inside the plain text. If you have a code snippet it looks better with the button.
sometimes I really hate that everyone formats logs their own way…
I have run into small issue. Some of the dates are not formatting correctly. I found out that there is a difference in log format based on the day. Not all days are double digit. So when the day is 1-9 the format below doesnt work because of the extra space. I tried to split each character to its own line…and the join them so that i can always get the same date format…it works but it looks like a jumbled mess.