This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
It's Easy to log a session in MSH,
you just use start-transcript and stop-transcript.
MSH>gc "C:\Documents and Settings\mow\My Documents\msh_transcript.20051129213303.txt"
**********************
MSH Transcript Start
Start time: 20051129213303
Username : CP340339-A\mow
Machine : CP340339-A (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is C:\Documents and Settings\mow\My Documents\msh_transcript.20051129213303.txt
MSH>stop-transcript
**********************
MSH Transcript End
End time: 20051129213308
**********************
You may have seen the big list of supported date formats in last post, that we could parse to a date-object ....
Now ....guess what .... this one was not on the List ;-(
So An example of using -Match and [dateTime]::Parse to get a "real" date from the used dateformat in the Logfile :
MSH>"20051129213308" -match "(....)(..)(..)(..)(..)(..)"
True
MSH>[Datetime]::parse([string]::join("-",$matches[1..3])+"T"+[string]::join(":",$matches[4..6]))
Tuesday, November 29, 2005 9:33:08 PM
so now you have a "real" date object to work with,
the regex is a bit lazy becouse I just used "." (any Char), ofcourse its better to check on Digits, just liked the example of using -match (b.t.w. could not do this with Match-string) and then using the Matches with a RangeOperator, showing the flexbility there.
*edit* Sorry, another Edit in 5 minutes but I realy did think I was to lazy,
here is the "better" version (checking for digits) :MSH>"20051129213308" -match "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})"
True
MSH>[Datetime]::parse([string]::join("-",$matches[1..3])+"T"+[string]::join(":",$matches[4..6]))
Tuesday, November 29, 2005 9:33:08 PM
but normal I still think I would prefer a RegEx-Object for this work.
e.g.:
$regex = new-object System.Text.RegularExpressions.regex("pattern")
You can than use the Replace Method of it, also I had a bit of problems with match-string doing this.
and the replace flexibility I like, also I know it a bit better from .NET and VBScript.But I did not play with match-string enough yet to make it final ;-), and I think the RegEx does deserve a blog entry on his own (altough you can find a lot of info on using regEx, already just try a Search in google)
anyway for small checks -match is ideal, and seems to work better as match-string.
Ohh, and yeah this was about logging, that works easy in Monad, altough I would have picked another date format for it ;-)
gr /\/\o\/\/