Jump to content

Recommended Posts

Posted

How can I get the Time and or Date of a computer on my network and set the value as a $var?

I tried to use "$Time = RunWait("net time \\192.168.1.123") but it just returns a 0 stating that the command completed.

Thanks,

GD

Posted

GoogleDude

$strComputer = "." ;remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = "Year: " & $objItem.Year  & @LF & _
                 "Quarter: " & $objItem.Quarter & @LF & _
                 "Month: " & $objItem.Month & @LF & _
                 "WeekInMonth: " & $objItem.WeekInMonth & @LF & _
                 "DayOfWeek: " & $objItem.DayOfWeek & @LF & _
                 "Day: " & $objItem.Day & @LF & _
                 "Hour: " & $objItem.Hour & @LF & _
                 "Minute: " & $objItem.Minute & @LF & _
                 "Second: " & $objItem.Second
Next

MsgBox(0, "", $strResult)

MSDN

Posted

Easy, just change the the str result string!

$strComputer = ".";remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = $objItem.Month & "/" & _
            $objItem.Day & "/" & _
            $objItem.Year & " " & _
            $objItem.Hour & ":" & _
            $objItem.Minute & ":" & _
            $objItem.Second & "(MM/DD/YYYY HH:MM:SS)"
Next


MsgBox(0, "", $strResult)

Hope it helps!

:mellow:

Cheers,

Brett

Posted

Easy, just change the the str result string!

$strComputer = ".";remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = $objItem.Month & "/" & _
            $objItem.Day & "/" & _
            $objItem.Year & " " & _
            $objItem.Hour & ":" & _
            $objItem.Minute & ":" & _
            $objItem.Second & "(MM/DD/YYYY HH:MM:SS)"
Next


MsgBox(0, "", $strResult)

Hope it helps!

:mellow:

Cheers,

Brett

It does. Thanks. I think I can achieve my goal with your above sample.

Thanks,

GD

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...