0

I need a script that reads from a txt file (a computer list) and returns how much time do we have before the Daylight savings starts.

Here's my script so far:

strComputer = "C:\temp\computerlist.txt"

For Each computer in strComputer

For Each objItem in colItems
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")
    strTime = objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second
    dtmTime = CDate(strTime)
    Wscript.Echo FormatDateTime(dtmTime, vbFormatLongTime)
Next
Next

DayLightSavingTimes=CDate("21/10/2013 00:00:00")


wscript.echo("It is " & DateDiff("m", Now(), DayLightSavingTimes) & " Months to the DayLightSavingTimes!")
wscript.echo("It is " &  DateDiff("d", Now(), DayLightSavingTimes) & " days to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("h", Now(), DayLightSavingTimes) & " hours to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("n", Now(), DayLightSavingTimes) & " Minutes to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("s", Now(), DayLightSavingTimes) & " seconds to the DayLightSavingTimes!")

When I ran this for one single computer it works:

strComputer = "MyComputer"
WScript.Echo "Running Against Remote Computer Named: " & strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")

For Each objItem in colItems
    strTime = objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second
    dtmTime = CDate(strTime)
    Wscript.Echo FormatDateTime(dtmTime, vbFormatLongTime)
Next


DayLightSavingTimes=CDate("21/10/2013 00:00:00")


wscript.echo("It is " & DateDiff("m", Now(), DayLightSavingTimes) & " Months to the DayLightSavingTimes!")
wscript.echo("It is " &  DateDiff("d", Now(), DayLightSavingTimes) & " days to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("h", Now(), DayLightSavingTimes) & " hours to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("n", Now(), DayLightSavingTimes) & " Minutes to the DayLightSavingTimes!")
wscript.echo("It is " & DateDiff("s", Now(), DayLightSavingTimes) & " seconds to the DayLightSavingTimes!")

And I get the expected results:

Running Against Remote Computer Named: MyComputer
14:28:22
It is 0 Months to the DayLightSavingTimes!
It is 3 days to the DayLightSavingTimes!
It is 58 hours to the DayLightSavingTimes!
It is 3452 Minutes to the DayLightSavingTimes!
It is 207098 seconds to the DayLightSavingTimes!

I need to get the same results running this on remote machines, stored on computerlist.txt The error I get running it remotely is Microsoft VBScript runtime error: Object not a collection.

Any hints?

Thanks

Bianca Borges
  • 175
  • 1
  • 3
  • 8
  • Is your question how to execute your code for each computer in computerlist.txt? That seems to me what you're asking given your initial code block that shows the filename and then an attempt to loop through the given string. – user5923 Oct 18 '13 at 17:39
  • Works for me. Do you get the error for all remote systems, or just for particular ones? Have you checked that WMI is working properly (with [`WBEMTest`](http://technet.microsoft.com/en-us/library/ee692770.aspx) or [WMIDiag](http://blogs.technet.com/b/askperf/archive/2012/02/03/wmidiag-2-1-is-here.aspx))? – Ansgar Wiechers Oct 21 '13 at 09:25

0 Answers0