![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | WMI Local Time format Can this be shortened? I'm trying to get the local date/time on some remote servers. $dt = gwmi win32_localtime [string]::format("{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}", $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) Shay http://scriptolog.blogspot.com |
My System Specs![]() |
| | #2 (permalink) |
| | Re: WMI Local Time format On Sep 11, 6:15 pm, Shay Levi <n...@xxxxxx> wrote: Quote: > Can this be shortened? I'm trying to get the local date/time on some remote > servers. > > $dt = gwmi win32_localtime > [string]::format("{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}", $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) > > Shayhttp://scriptolog.blogspot.com "{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}" -f $dt.month,$dt.day,$dt.year, $dt.hour,$dt.minute,$dt.second It looks to me that $dt.month slipped in there by mistake.... Jeff |
My System Specs![]() |
| | #3 (permalink) |
| | Re: WMI Local Time format On Sep 11, 8:39 pm, Jeff <jeff.hill...@xxxxxx> wrote: Quote: > On Sep 11, 6:15 pm, Shay Levi <n...@xxxxxx> wrote: > Quote: > > Can this be shortened? I'm trying to get the local date/time on some remote > > servers. Quote: > > $dt = gwmi win32_localtime > > [string]::format("{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}", $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) Quote: > > Shayhttp://scriptolog.blogspot.com > This is slightly shorter, and it appears to give you the correct time: > > "{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}" -f $dt.month,$dt.day,$dt.year, > $dt.hour,$dt.minute,$dt.second > > It looks to me that $dt.month slipped in there by mistake.... > > Jeff slightly shorter: New-Object DateTime $dt.year,$dt.month,$dt.day,$dt.hour,$dt.minute, $dt.second Jeff |
My System Specs![]() |
| | #4 (permalink) |
| | Re: WMI Local Time format Thanks Jeff. Shay http://scriptolog.blogspot.com Quote: > On Sep 11, 8:39 pm, Jeff <jeff.hill...@xxxxxx> wrote: > Quote: >> On Sep 11, 6:15 pm, Shay Levi <n...@xxxxxx> wrote: >> Quote: >>> Can this be shortened? I'm trying to get the local date/time on some >>> remote servers. >>> >>> $dt = gwmi win32_localtime >>> [string]::format("{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}", >>> $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) >>> Shayhttp://scriptolog.blogspot.com >>> >> time: >> >> "{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}" -f >> $dt.month,$dt.day,$dt.year, $dt.hour,$dt.minute,$dt.second >> >> It looks to me that $dt.month slipped in there by mistake.... >> >> Jeff >> > slightly shorter: > > New-Object DateTime $dt.year,$dt.month,$dt.day,$dt.hour,$dt.minute, > $dt.second > > Jeff > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: WMI Local Time format "Shay Levi" <no@xxxxxx> wrote in message news:8766a9446e518c9c29567c88318@xxxxxx Quote: > > Can this be shortened? I'm trying to get the local date/time on some > remote servers. > > $dt = gwmi win32_localtime > [string]::format("{0:00}/{1:00}/{2} {3:00}:{4:00}:{5:00}", > $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) which sounds like it should provide what you are looking for. However I can't make it work. If someone from the PowerShell team reads this, they might tell us a bit more about it? Jacques |
My System Specs![]() |
| | #6 (permalink) |
| | Re: WMI Local Time format Thanks Jacques. When piping $dt to get-member I saw it too. Eventually, I got the time by querying the Win32_OperatingSystem class, It has a LocalDateTime property, (Win32_LocalTime isnt available on W2K boxes). which is what ConvertToDateTime() accepts as an argument. $dt = (gwmi -query "select LocalDateTime from win32_operatingsystem").LocalDateTime ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss") Shay http://scriptolog.blogspot.com Quote: > "Shay Levi" <no@xxxxxx> wrote in message > news:8766a9446e518c9c29567c88318@xxxxxx > Quote: >> Can this be shortened? I'm trying to get the local date/time on some >> remote servers. >> >> $dt = gwmi win32_localtime [string]::format("{0:00}/{1:00}/{2} >> {3:00}:{4:00}:{5:00}", >> $dt.month,$dt.day,$dt.year,$dt.month,$dt.hour,$dt.minute,$dt.second) >> > ConvertToDateTime() which sounds like it should provide what you are > looking for. However I can't make it work. > > If someone from the PowerShell team reads this, they might tell us a > bit more about it? > > Jacques > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Converting date time format to string format | PowerShell | |||
| Photo Gallery Date/Time Format | Vista file management | |||
| why need much more time to format USB drive media | Vista hardware & devices | |||
| why need much more time to format USB drive media | Vista hardware & devices | |||
| I don't have enough time to get rid of bugs I need to format HDD. | Vista General | |||