• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Get time from a remote server with PowerShell v2

M

Mehdis

#1
Hi all,

I'm looking for a way to obtain the time from a remote server. I wanted to
use Get-Date but this doesnt seem to have any options for remote computers so
I'm using WMI Win32_LocalTime option like this:

$hour = Get-WmiObject Win32_LocalTime -computerName servername |
Select-Object -Property Hour
$minute = Get-WmiObject Win32_LocalTime -computerName servername |
Select-Object -Property Minute
$second = Get-WmiObject Wind32_LocalTime -computerName servername |
Select-Object -Property Second

However this returns values in the form of (for example):

@{Hour=16}
@{Minute=26}
@{Second=30}

Is there an easy way to obtain the time from a remote server as just a
numeric value without the '@{Hour=' e.t.c?

Any advice or suggestions would be much appreciated.
Many thanks
Mehds
 

My Computer

Q

qa_warrior

#2
On Jan 22, 4:30 am, Mehdis <Meh...@newsgroup> wrote:

> Hi all,
>
> I'm looking for a way to obtain the time from a remote server. I wanted to
> use Get-Date but this doesnt seem to have any options for remote computers so
> I'm using WMI Win32_LocalTime option like this:
>
> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Hour
> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Minute
> $second = Get-WmiObject Wind32_LocalTime -computerName servername |
> Select-Object -Property Second
>
> However this returns values in the form of (for example):
>
> @{Hour=16}
> @{Minute=26}
> @{Second=30}
>
> Is there an easy way to obtain the time from a remote server as just a
> numeric value without the '@{Hour=' e.t.c?
>
> Any advice or suggestions would be much appreciated.
> Many thanks
> Mehds
Is PsRemoting Enabled? If So You Could Invoke-Command on the remote
server to return Get-Date -Format HH:mm:ss
 

My Computer

K

Karl Mitschke

#3
Hello Mehdis,

> Hi all,
>
> I'm looking for a way to obtain the time from a remote server. I
> wanted to use Get-Date but this doesnt seem to have any options for
> remote computers so I'm using WMI Win32_LocalTime option like this:
>
> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Hour
> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Minute
> $second = Get-WmiObject Wind32_LocalTime -computerName servername |
> Select-Object -Property Second
> However this returns values in the form of (for example):
>
> @{Hour=16}
> @{Minute=26}
> @{Second=30}
> Is there an easy way to obtain the time from a remote server as just a
> numeric value without the '@{Hour=' e.t.c?
>
> Any advice or suggestions would be much appreciated.
> Many thanks
> Mehds
Hi;

Try this, taken from http://www.vistax64.com/powershell/91254-wmi-local-time-format.html
:

$dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from win32_operatingsystem").LocalDateTime
([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")

You can change the format on the second line ("MM/dd/yyyy HH:mm:ss") to suit
your needs

Karl
http://unlockpowershell.wordpress.com/
 

My Computer

M

Martin Zugec

#4
Hi Mehdis,

you can use Get-WmiObject Win32_OperatingSystem and retrieve LocalDateTime.

In order to convert it to regular [DateTime], use
([wmi]'').ConvertToDateTime() function

Martin

"Mehdis" <Mehdis@newsgroup> wrote in message
news:E126F784-858F-4FC0-80D3-6E41D0499CF7@newsgroup

> Hi all,
>
> I'm looking for a way to obtain the time from a remote server. I wanted to
> use Get-Date but this doesnt seem to have any options for remote computers
> so
> I'm using WMI Win32_LocalTime option like this:
>
> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Hour
> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> Select-Object -Property Minute
> $second = Get-WmiObject Wind32_LocalTime -computerName servername |
> Select-Object -Property Second
>
> However this returns values in the form of (for example):
>
> @{Hour=16}
> @{Minute=26}
> @{Second=30}
>
> Is there an easy way to obtain the time from a remote server as just a
> numeric value without the '@{Hour=' e.t.c?
>
> Any advice or suggestions would be much appreciated.
> Many thanks
> Mehds
 

My Computer

M

Mehdis

#5
Hi qa_warrior, thanks I didn'y know about that command. I did it as:

Invoke-Command -ComputerName servername -ScriptBlock{Get-Date -Format
HH:mm:ss}

However it's a little slow on getting the result. Using WMI is a lot faster.

Thanks again.

"qa_warrior" wrote:

> On Jan 22, 4:30 am, Mehdis <Meh...@newsgroup> wrote:

> > Hi all,
> >
> > I'm looking for a way to obtain the time from a remote server. I wanted to
> > use Get-Date but this doesnt seem to have any options for remote computers so
> > I'm using WMI Win32_LocalTime option like this:
> >
> > $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> > Select-Object -Property Hour
> > $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> > Select-Object -Property Minute
> > $second = Get-WmiObject Wind32_LocalTime -computerName servername |
> > Select-Object -Property Second
> >
> > However this returns values in the form of (for example):
> >
> > @{Hour=16}
> > @{Minute=26}
> > @{Second=30}
> >
> > Is there an easy way to obtain the time from a remote server as just a
> > numeric value without the '@{Hour=' e.t.c?
> >
> > Any advice or suggestions would be much appreciated.
> > Many thanks
> > Mehds
>
> Is PsRemoting Enabled? If So You Could Invoke-Command on the remote
> server to return Get-Date -Format HH:mm:ss
> .
>
 

My Computer

M

Mehdis

#6
I'm running on windows 7 at the moment. The last line you gave me worked
giving the following:

CurrentTimeZone : 0
LastBootUpTime : 20100126114414.375199+000
LocalDateTime : 20100126171322.660000+000



"Karl Mitschke" wrote:

> Hello Mehdis,
>

> > Hi Karl, thanks for this info and link. Unfortuantely I couldnt get it
> > running. I kept getting:
> >
> > Method invocation failed because
> > [System.Management.ManagementObject#\Win32_OperatingSystem] doesn't
> > contain a method named 'LocalDateTime'.
> >
> > "Karl Mitschke" wrote:
> >

> >> Hello Mehdis,
> >>
> >>> Hi all,
> >>>
> >>> I'm looking for a way to obtain the time from a remote server. I
> >>> wanted to use Get-Date but this doesnt seem to have any options for
> >>> remote computers so I'm using WMI Win32_LocalTime option like this:
> >>>
> >>> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> >>> Select-Object -Property Hour
> >>> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> >>> Select-Object -Property Minute
> >>> $second = Get-WmiObject Wind32_LocalTime -computerName servername |
> >>> Select-Object -Property Second
> >>> However this returns values in the form of (for example):
> >>> @{Hour=16}
> >>> @{Minute=26}
> >>> @{Second=30}
> >>> Is there an easy way to obtain the time from a remote server as just
> >>> a
> >>> numeric value without the '@{Hour=' e.t.c?
> >>> Any advice or suggestions would be much appreciated.
> >>> Many thanks
> >>> Mehds
> >> Hi;
> >>
> >> Try this, taken from
> >> http://www.vistax64.com/powershell/91254-wmi-local-time-format.html :
> >>
> >> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
> >> win32_operatingsystem").LocalDateTime
> >>
> >> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
> >>
> >> You can change the format on the second line ("MM/dd/yyyy HH:mm:ss")
> >> to suit your needs
> >>
> >> Karl
> >> http://unlockpowershell.wordpress.com/
> >> .
> >>
>
> That's strange.
>
> What OS?
>
> Try this:
> Get-WmiObject Win32_OperatingSystem |Format-List *time*
>
> Karl
> http://unlockpowershell.wordpress.com/
>
>
> .
>
 

My Computer

K

Karl Mitschke

#7
Hello Mehdis,

> I'm running on windows 7 at the moment. The last line you gave me
> worked giving the following:
>
> CurrentTimeZone : 0
> LastBootUpTime : 20100126114414.375199+000
> LocalDateTime : 20100126171322.660000+000
> "Karl Mitschke" wrote:
>

>> Hello Mehdis,
>>

>>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt get
>>> it running. I kept getting:
>>>
>>> Method invocation failed because
>>> [System.Management.ManagementObject#\Win32_OperatingSystem] doesn't
>>> contain a method named 'LocalDateTime'.
>>>
>>> "Karl Mitschke" wrote:
>>>
>>>> Hello Mehdis,
>>>>
>>>>> Hi all,
>>>>>
>>>>> I'm looking for a way to obtain the time from a remote server. I
>>>>> wanted to use Get-Date but this doesnt seem to have any options
>>>>> for remote computers so I'm using WMI Win32_LocalTime option like
>>>>> this:
>>>>>
>>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
>>>>> Select-Object -Property Hour
>>>>> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
>>>>> Select-Object -Property Minute
>>>>> $second = Get-WmiObject Wind32_LocalTime -computerName servername
>>>>> |
>>>>> Select-Object -Property Second
>>>>> However this returns values in the form of (for example):
>>>>> @{Hour=16}
>>>>> @{Minute=26}
>>>>> @{Second=30}
>>>>> Is there an easy way to obtain the time from a remote server as
>>>>> just
>>>>> a
>>>>> numeric value without the '@{Hour=' e.t.c?
>>>>> Any advice or suggestions would be much appreciated.
>>>>> Many thanks
>>>>> Mehds
>>>> Hi;
>>>>
>>>> Try this, taken from
>>>> http://www.vistax64.com/powershell/91254-wmi-local-time-format.html
>>>> :
>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
>>>> win32_operatingsystem").LocalDateTime
>>>>
>>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
>>>>
>>>> You can change the format on the second line ("MM/dd/yyyy
>>>> HH:mm:ss") to suit your needs
>>>>
>>>> Karl
>>>> http://unlockpowershell.wordpress.com/
>>>> .
>> That's strange.
>>
>> What OS?
>>
>> Try this:
>> Get-WmiObject Win32_OperatingSystem |Format-List *time*
>> Karl
>> http://unlockpowershell.wordpress.com/
>> .
>>
OK, So we know the error you received is invalid.

Try this (one line)

$dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from win32_operatingsystem").LocalDateTime
#dt

Karl
http://unlockpowershell.wordpress.com/
 

My Computer

M

Mehdis

#8
Hi Karl, thanks again for your help, that one works too, giving:

20100127103947.257000+000

On another forum someone suggested using exapandProperty:

$hour = Get-WmiObject Win32_LocalTime -computerName webserver2 |
Select-Object -expandProperty Hour

.....and then obviously do this for minute and second too.

Located here:
http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/4655/afv/topic/Default.aspx

I guess its another option.

"Karl Mitschke" wrote:

> Hello Mehdis,
>

> > I'm running on windows 7 at the moment. The last line you gave me
> > worked giving the following:
> >
> > CurrentTimeZone : 0
> > LastBootUpTime : 20100126114414.375199+000
> > LocalDateTime : 20100126171322.660000+000
> > "Karl Mitschke" wrote:
> >

> >> Hello Mehdis,
> >>
> >>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt get
> >>> it running. I kept getting:
> >>>
> >>> Method invocation failed because
> >>> [System.Management.ManagementObject#\Win32_OperatingSystem] doesn't
> >>> contain a method named 'LocalDateTime'.
> >>>
> >>> "Karl Mitschke" wrote:
> >>>
> >>>> Hello Mehdis,
> >>>>
> >>>>> Hi all,
> >>>>>
> >>>>> I'm looking for a way to obtain the time from a remote server. I
> >>>>> wanted to use Get-Date but this doesnt seem to have any options
> >>>>> for remote computers so I'm using WMI Win32_LocalTime option like
> >>>>> this:
> >>>>>
> >>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> >>>>> Select-Object -Property Hour
> >>>>> $minute = Get-WmiObject Win32_LocalTime -computerName servername |
> >>>>> Select-Object -Property Minute
> >>>>> $second = Get-WmiObject Wind32_LocalTime -computerName servername
> >>>>> |
> >>>>> Select-Object -Property Second
> >>>>> However this returns values in the form of (for example):
> >>>>> @{Hour=16}
> >>>>> @{Minute=26}
> >>>>> @{Second=30}
> >>>>> Is there an easy way to obtain the time from a remote server as
> >>>>> just
> >>>>> a
> >>>>> numeric value without the '@{Hour=' e.t.c?
> >>>>> Any advice or suggestions would be much appreciated.
> >>>>> Many thanks
> >>>>> Mehds
> >>>> Hi;
> >>>>
> >>>> Try this, taken from
> >>>> http://www.vistax64.com/powershell/91254-wmi-local-time-format.html
> >>>> :
> >>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
> >>>> win32_operatingsystem").LocalDateTime
> >>>>
> >>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
> >>>>
> >>>> You can change the format on the second line ("MM/dd/yyyy
> >>>> HH:mm:ss") to suit your needs
> >>>>
> >>>> Karl
> >>>> http://unlockpowershell.wordpress.com/
> >>>> .
> >> That's strange.
> >>
> >> What OS?
> >>
> >> Try this:
> >> Get-WmiObject Win32_OperatingSystem |Format-List *time*
> >> Karl
> >> http://unlockpowershell.wordpress.com/
> >> .
> >>
>
> OK, So we know the error you received is invalid.
>
> Try this (one line)
>
> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from win32_operatingsystem").LocalDateTime
> #dt
>
> Karl
> http://unlockpowershell.wordpress.com/
>
>
> .
>
 

My Computer

K

Karl Mitschke

#9
Hello Mehdis,

> Hi Karl, thanks again for your help, that one works too, giving:
>
> 20100127103947.257000+000
Then, if $dt = 20100127103947.257000+000, the second line should run fine:


([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")

Karl


> On another forum someone suggested using exapandProperty:
>
> $hour = Get-WmiObject Win32_LocalTime -computerName webserver2 |
> Select-Object -expandProperty Hour
>
> ....and then obviously do this for minute and second too.
>
> Located here:
> http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/4655/afv/topi
> c/Default.aspx
> I guess its another option.
>
> "Karl Mitschke" wrote:
>

>> Hello Mehdis,
>>

>>> I'm running on windows 7 at the moment. The last line you gave me
>>> worked giving the following:
>>>
>>> CurrentTimeZone : 0
>>> LastBootUpTime : 20100126114414.375199+000
>>> LocalDateTime : 20100126171322.660000+000
>>> "Karl Mitschke" wrote:
>>>> Hello Mehdis,
>>>>
>>>>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt
>>>>> get it running. I kept getting:
>>>>>
>>>>> Method invocation failed because
>>>>> [System.Management.ManagementObject#\Win32_OperatingSystem]
>>>>> doesn't contain a method named 'LocalDateTime'.
>>>>>
>>>>> "Karl Mitschke" wrote:
>>>>>
>>>>>> Hello Mehdis,
>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I'm looking for a way to obtain the time from a remote server. I
>>>>>>> wanted to use Get-Date but this doesnt seem to have any options
>>>>>>> for remote computers so I'm using WMI Win32_LocalTime option
>>>>>>> like this:
>>>>>>>
>>>>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
>>>>>>> Select-Object -Property Hour
>>>>>>> $minute = Get-WmiObject Win32_LocalTime -computerName servername
>>>>>>> |
>>>>>>> Select-Object -Property Minute
>>>>>>> $second = Get-WmiObject Wind32_LocalTime -computerName
>>>>>>> servername
>>>>>>> |
>>>>>>> Select-Object -Property Second
>>>>>>> However this returns values in the form of (for example):
>>>>>>> @{Hour=16}
>>>>>>> @{Minute=26}
>>>>>>> @{Second=30}
>>>>>>> Is there an easy way to obtain the time from a remote server as
>>>>>>> just
>>>>>>> a
>>>>>>> numeric value without the '@{Hour=' e.t.c?
>>>>>>> Any advice or suggestions would be much appreciated.
>>>>>>> Many thanks
>>>>>>> Mehds
>>>>>> Hi;
>>>>>>
>>>>>> Try this, taken from
>>>>>> http://www.vistax64.com/powershell/91254-wmi-local-time-format.ht
>>>>>> ml
>>>>>> :
>>>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime
>>>>>> from
>>>>>> win32_operatingsystem").LocalDateTime
>>>>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
>>>>>>
>>>>>> You can change the format on the second line ("MM/dd/yyyy
>>>>>> HH:mm:ss") to suit your needs
>>>>>>
>>>>>> Karl
>>>>>> http://unlockpowershell.wordpress.com/
>>>>>> .
>>>> That's strange.
>>>>
>>>> What OS?
>>>>
>>>> Try this:
>>>> Get-WmiObject Win32_OperatingSystem |Format-List *time*
>>>> Karl
>>>> http://unlockpowershell.wordpress.com/
>>>> .
>> OK, So we know the error you received is invalid.
>>
>> Try this (one line)
>>
>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
>> win32_operatingsystem").LocalDateTime
>>
>> #dt
>>
>> Karl
>> http://unlockpowershell.wordpress.com/
>> .
>>
Karl
http://unlockpowershell.wordpress.com/
 

My Computer

M

Mehdis

#10
Yes it works now. I made the mistake of leaving them on the same line when I
pasted into my script editor. Thank you for your help!

"Karl Mitschke" wrote:

> Hello Mehdis,
>

> > Hi Karl, thanks again for your help, that one works too, giving:
> >
> > 20100127103947.257000+000
>
> Then, if $dt = 20100127103947.257000+000, the second line should run fine:
>
>
> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
>
> Karl
>
>

> > On another forum someone suggested using exapandProperty:
> >
> > $hour = Get-WmiObject Win32_LocalTime -computerName webserver2 |
> > Select-Object -expandProperty Hour
> >
> > ....and then obviously do this for minute and second too.
> >
> > Located here:
> > http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/4655/afv/topi
> > c/Default.aspx
> > I guess its another option.
> >
> > "Karl Mitschke" wrote:
> >

> >> Hello Mehdis,
> >>
> >>> I'm running on windows 7 at the moment. The last line you gave me
> >>> worked giving the following:
> >>>
> >>> CurrentTimeZone : 0
> >>> LastBootUpTime : 20100126114414.375199+000
> >>> LocalDateTime : 20100126171322.660000+000
> >>> "Karl Mitschke" wrote:
> >>>> Hello Mehdis,
> >>>>
> >>>>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt
> >>>>> get it running. I kept getting:
> >>>>>
> >>>>> Method invocation failed because
> >>>>> [System.Management.ManagementObject#\Win32_OperatingSystem]
> >>>>> doesn't contain a method named 'LocalDateTime'.
> >>>>>
> >>>>> "Karl Mitschke" wrote:
> >>>>>
> >>>>>> Hello Mehdis,
> >>>>>>
> >>>>>>> Hi all,
> >>>>>>>
> >>>>>>> I'm looking for a way to obtain the time from a remote server. I
> >>>>>>> wanted to use Get-Date but this doesnt seem to have any options
> >>>>>>> for remote computers so I'm using WMI Win32_LocalTime option
> >>>>>>> like this:
> >>>>>>>
> >>>>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername |
> >>>>>>> Select-Object -Property Hour
> >>>>>>> $minute = Get-WmiObject Win32_LocalTime -computerName servername
> >>>>>>> |
> >>>>>>> Select-Object -Property Minute
> >>>>>>> $second = Get-WmiObject Wind32_LocalTime -computerName
> >>>>>>> servername
> >>>>>>> |
> >>>>>>> Select-Object -Property Second
> >>>>>>> However this returns values in the form of (for example):
> >>>>>>> @{Hour=16}
> >>>>>>> @{Minute=26}
> >>>>>>> @{Second=30}
> >>>>>>> Is there an easy way to obtain the time from a remote server as
> >>>>>>> just
> >>>>>>> a
> >>>>>>> numeric value without the '@{Hour=' e.t.c?
> >>>>>>> Any advice or suggestions would be much appreciated.
> >>>>>>> Many thanks
> >>>>>>> Mehds
> >>>>>> Hi;
> >>>>>>
> >>>>>> Try this, taken from
> >>>>>> http://www.vistax64.com/powershell/91254-wmi-local-time-format.ht
> >>>>>> ml
> >>>>>> :
> >>>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime
> >>>>>> from
> >>>>>> win32_operatingsystem").LocalDateTime
> >>>>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
> >>>>>>
> >>>>>> You can change the format on the second line ("MM/dd/yyyy
> >>>>>> HH:mm:ss") to suit your needs
> >>>>>>
> >>>>>> Karl
> >>>>>> http://unlockpowershell.wordpress.com/
> >>>>>> .
> >>>> That's strange.
> >>>>
> >>>> What OS?
> >>>>
> >>>> Try this:
> >>>> Get-WmiObject Win32_OperatingSystem |Format-List *time*
> >>>> Karl
> >>>> http://unlockpowershell.wordpress.com/
> >>>> .
> >> OK, So we know the error you received is invalid.
> >>
> >> Try this (one line)
> >>
> >> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
> >> win32_operatingsystem").LocalDateTime
> >>
> >> #dt
> >>
> >> Karl
> >> http://unlockpowershell.wordpress.com/
> >> .
> >>
>
> Karl
> http://unlockpowershell.wordpress.com/
>
>
> .
>
 

My Computer

K

Karl Mitschke

#11
Hello Mehdis,

You are welcome.

Karl

> Yes it works now. I made the mistake of leaving them on the same line
> when I pasted into my script editor. Thank you for your help!
>
> "Karl Mitschke" wrote:
>

>> Hello Mehdis,
>>

>>> Hi Karl, thanks again for your help, that one works too, giving:
>>>
>>> 20100127103947.257000+000
>>>
>> Then, if $dt = 20100127103947.257000+000, the second line should run
>> fine:
>>
>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
>>
>> Karl
>>

>>> On another forum someone suggested using exapandProperty:
>>>
>>> $hour = Get-WmiObject Win32_LocalTime -computerName webserver2 |
>>> Select-Object -expandProperty Hour
>>>
>>> ....and then obviously do this for minute and second too.
>>>
>>> Located here:
>>> http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/4655/afv/to
>>> pi
>>> c/Default.aspx
>>> I guess its another option.
>>> "Karl Mitschke" wrote:
>>>
>>>> Hello Mehdis,
>>>>
>>>>> I'm running on windows 7 at the moment. The last line you gave me
>>>>> worked giving the following:
>>>>>
>>>>> CurrentTimeZone : 0
>>>>> LastBootUpTime : 20100126114414.375199+000
>>>>> LocalDateTime : 20100126171322.660000+000
>>>>> "Karl Mitschke" wrote:
>>>>>> Hello Mehdis,
>>>>>>
>>>>>>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt
>>>>>>> get it running. I kept getting:
>>>>>>>
>>>>>>> Method invocation failed because
>>>>>>> [System.Management.ManagementObject#\Win32_OperatingSystem]
>>>>>>> doesn't contain a method named 'LocalDateTime'.
>>>>>>>
>>>>>>> "Karl Mitschke" wrote:
>>>>>>>
>>>>>>>> Hello Mehdis,
>>>>>>>>
>>>>>>>>> Hi all,
>>>>>>>>>
>>>>>>>>> I'm looking for a way to obtain the time from a remote server.
>>>>>>>>> I wanted to use Get-Date but this doesnt seem to have any
>>>>>>>>> options for remote computers so I'm using WMI Win32_LocalTime
>>>>>>>>> option like this:
>>>>>>>>>
>>>>>>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername
>>>>>>>>> |
>>>>>>>>> Select-Object -Property Hour
>>>>>>>>> $minute = Get-WmiObject Win32_LocalTime -computerName
>>>>>>>>> servername
>>>>>>>>> |
>>>>>>>>> Select-Object -Property Minute
>>>>>>>>> $second = Get-WmiObject Wind32_LocalTime -computerName
>>>>>>>>> servername
>>>>>>>>> |
>>>>>>>>> Select-Object -Property Second
>>>>>>>>> However this returns values in the form of (for example):
>>>>>>>>> @{Hour=16}
>>>>>>>>> @{Minute=26}
>>>>>>>>> @{Second=30}
>>>>>>>>> Is there an easy way to obtain the time from a remote server
>>>>>>>>> as
>>>>>>>>> just
>>>>>>>>> a
>>>>>>>>> numeric value without the '@{Hour=' e.t.c?
>>>>>>>>> Any advice or suggestions would be much appreciated.
>>>>>>>>> Many thanks
>>>>>>>>> Mehds
>>>>>>>> Hi;
>>>>>>>>
>>>>>>>> Try this, taken from
>>>>>>>> http://www.vistax64.com/powershell/91254-wmi-local-time-format.
>>>>>>>> ht
>>>>>>>> ml
>>>>>>>> :
>>>>>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime
>>>>>>>> from
>>>>>>>> win32_operatingsystem").LocalDateTime
>>>>>>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy
>>>>>>>> HH:mm:ss")
>>>>>>>> You can change the format on the second line ("MM/dd/yyyy
>>>>>>>> HH:mm:ss") to suit your needs
>>>>>>>>
>>>>>>>> Karl
>>>>>>>> http://unlockpowershell.wordpress.com/
>>>>>>>> .
>>>>>> That's strange.
>>>>>>
>>>>>> What OS?
>>>>>>
>>>>>> Try this:
>>>>>> Get-WmiObject Win32_OperatingSystem |Format-List *time*
>>>>>> Karl
>>>>>> http://unlockpowershell.wordpress.com/
>>>>>> .
>>>> OK, So we know the error you received is invalid.
>>>>
>>>> Try this (one line)
>>>>
>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
>>>> win32_operatingsystem").LocalDateTime
>>>>
>>>> #dt
>>>>
>>>> Karl
>>>> http://unlockpowershell.wordpress.com/
>>>> .
>> Karl
>> http://unlockpowershell.wordpress.com/
>> .
>>
Karl
http://unlockpowershell.wordpress.com/
 

My Computer

A

Ashraf

#12
On Jan 28, 10:26 am, Karl Mitschke <karlmitsc...@newsgroup> wrote:

> Hello Mehdis,
>
> You are welcome.
>
> Karl
>
>
>
>
>

> > Yes it works now. I made the mistake of leaving them on the same line
> > when I pasted into my script editor. Thank you for your help!
>

> > "Karl Mitschke" wrote:
> >

> >>> Hi Karl, thanks again for your help, that one works too, giving:
>

> >>> 20100127103947.257000+000
>

> >> Then, if $dt = 20100127103947.257000+000, the second line should run
> >> fine:
>

> >> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy HH:mm:ss")
> >

> >>> On another forum someone suggested using exapandProperty:
>

> >>> $hour = Get-WmiObject Win32_LocalTime -computerName webserver2 |
> >>> Select-Object -expandProperty Hour
>

> >>> ....and then obviously do this for minute and second too.
>

> >>> Located here:
> >>>http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/4655/afv/to
> >>> pi
> >>> c/Default.aspx
> >>> I guess its another option.
> >>> "Karl Mitschke" wrote:
>

> >>>> Hello Mehdis,
>

> >>>>> I'm running on windows 7 at the moment. The last line you gave me
> >>>>> worked giving the following:
>

> >>>>> CurrentTimeZone : 0
> >>>>> LastBootUpTime  : 20100126114414.375199+000
> >>>>> LocalDateTime   : 20100126171322.660000+000
> >>>>> "Karl Mitschke" wrote:
> >>>>>> Hello Mehdis,
>

> >>>>>>> Hi Karl, thanks for this info and link. Unfortuantely I couldnt
> >>>>>>> get it running. I kept getting:
>

> >>>>>>> Method invocation failed because
> >>>>>>> [System.Management.ManagementObject#\Win32_OperatingSystem]
> >>>>>>> doesn't contain a method named 'LocalDateTime'.
>

> >>>>>>> "Karl Mitschke" wrote:
>

> >>>>>>>> Hello Mehdis,
> >

> >>>>>>>>> I'm looking for a way to obtain the time from a remote server.
> >>>>>>>>> I wanted to use Get-Date but this doesnt seem to have any
> >>>>>>>>> options for remote computers so I'm using WMI Win32_LocalTime
> >>>>>>>>> option like this:
>

> >>>>>>>>> $hour = Get-WmiObject Win32_LocalTime -computerName servername
> >>>>>>>>> |
> >>>>>>>>> Select-Object -Property Hour
> >>>>>>>>> $minute = Get-WmiObject Win32_LocalTime -computerName
> >>>>>>>>> servername
> >>>>>>>>> |
> >>>>>>>>> Select-Object -Property Minute
> >>>>>>>>> $second = Get-WmiObject Wind32_LocalTime -computerName
> >>>>>>>>> servername
> >>>>>>>>> |
> >>>>>>>>> Select-Object -Property Second
> >>>>>>>>> However this returns values in the form of (for example):
> >>>>>>>>> @{Hour=16}
> >>>>>>>>> @{Minute=26}
> >>>>>>>>> @{Second=30}
> >>>>>>>>> Is there an easy way to obtain the time from a remote server
> >>>>>>>>> as
> >>>>>>>>> just
> >>>>>>>>> a
> >>>>>>>>> numeric value without the '@{Hour=' e.t.c?
> >>>>>>>>> Any advice or suggestions would be much appreciated.
> >>>>>>>>> Many thanks
> >>>>>>>>> Mehds
> >>>>>>>> Hi;
>

> >>>>>>>> Try this, taken from
> >>>>>>>>http://www.vistax64.com/powershell/91254-wmi-local-time-format.
> >>>>>>>> ht
> >>>>>>>> ml
> >>>>>>>> :
> >>>>>>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime
> >>>>>>>> from
> >>>>>>>> win32_operatingsystem").LocalDateTime
> >>>>>>>> ([wmi]'').ConvertToDateTime($dt).tostring("MM/dd/yyyy
> >>>>>>>> HH:mm:ss")
> >>>>>>>> You can change the format on the second line ("MM/dd/yyyy
> >>>>>>>> HH:mm:ss") to suit your needs
>

> >>>>>>>> Karl
> >>>>>>>>http://unlockpowershell.wordpress.com/
> >>>>>>>> .
> >>>>>> That's strange.
> >

> >>>>>> Try this:
> >>>>>> Get-WmiObject Win32_OperatingSystem |Format-List *time*
> >>>>>> Karl
> >>>>>>http://unlockpowershell.wordpress.com/
> >>>>>> .
> >>>> OK, So we know the error you received is invalid.
>

> >>>> Try this (one line)
>

> >>>> $dt = (Get-WmiObject-ComputerName -Query "select LocalDateTime from
> >>>> win32_operatingsystem").LocalDateTime
> > >
> Karlhttp://unlockpowershell.wordpress.com/
Great help.
That works fine
([wmi]'').ConvertToDateTime((Get-WmiObject -ComputerName $servername -
Query "select LocalDateTime from
win32_operatingsystem").LocalDateTime).tostring("MMM dd,yyyy
HH:mm:ss")

Thanks
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)