Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Problem formatting date

Reply
 
Old 11-14-2007   #1 (permalink)
Jobbsy


 
 

Problem formatting date

I have obtained the date from particular eventlog entries but require the day
and month to swap order (dd/mm/yyyy to mm/dd/yyyy) in order to be able to
compare to pwdlastset obtained from ADSI - I have come up with the following
but although it seems to work it provides reoccuring output - can someone
offer as to why?

Many Thanks

$events = get-eventlog Security -newest 2000 | where {($_.EventID -eq 642)
-and ($_.UserName -eq "TestDomain\Administrator")}
Foreach($event in $events)#{Write-Host $Event.TimeWritten}
{
$EVT = "$($Event.TimeWritten)"

$EVTConvertedDate = "{00:MM}/{00:dd}/{0000:yyyy} {0:hh}:{0:mm}:{0:ss}" -f
($EVT)

write-host "$EVTConvertedDate"
}

--
jobbsy@xxxxxx

My System SpecsSystem Spec
Old 11-14-2007   #2 (permalink)
Shay Levi


 
 

Re: Problem formatting date

You can try ToString():

$EVT.TimeWritten.ToString("MM/dd/yyyy")


or the date format operator

$EVTConvertedDate = "{0:MM/dd/yyyy}" -f $EVT.TimeWritten


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> I have obtained the date from particular eventlog entries but require
> the day and month to swap order (dd/mm/yyyy to mm/dd/yyyy) in order to
> be able to compare to pwdlastset obtained from ADSI - I have come up
> with the following but although it seems to work it provides
> reoccuring output - can someone offer as to why?
>
> Many Thanks
>
> $events = get-eventlog Security -newest 2000 | where {($_.EventID -eq
> 642)
> -and ($_.UserName -eq "TestDomain\Administrator")}
> Foreach($event in $events)#{Write-Host $Event.TimeWritten}
> {
> $EVT = "$($Event.TimeWritten)"
> $EVTConvertedDate = "{00:MM}/{00:dd}/{0000:yyyy} {0:hh}:{0:mm}:{0:ss}"
> -f ($EVT)
>
> write-host "$EVTConvertedDate"
> }

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Problem formatting a dvd Vista music pictures video
date time formatting .NET General
date formatting PowerShell
Formatting Problem Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46