Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Daylight saving time script - to confirm current status

Reply
Thread Tools Display Modes

Re: Daylight saving time script - to confirm current status

 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      09-24-2008

"Stuart" <> wrote in message
news:b60fa100-9679-426e-bf1b-...
> Hi Everyone,
>
> I have a (very) large group of servers of which I need to confirm the
> DST status.. I have found the following script which will do the job i
> think, but i would like it to look at a source text file which
> contains the complete server list, then output the result to another
> text file.. is this possible? It would work like this...
>
> Look at first server name in c:\ source.txt, run script, output result
> to c:\results.txt
> Look at second server name
> Look at third server name.... etc etc...
>
> I would appreciate any help..
>
> Thanks,
> Stuart.
>
> +++++++++++++++++++++++++++++++++
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> Win32_ComputerSystem")
> For Each objItem In colItems
> WScript.Echo "Current Time Zone (Hours Offset From GMT): " &
> (objItem.CurrentTimeZone / 60)
> WScript.Echo "Daylight Saving In Effect: " &
> objItem.DaylightInEffect
> Next
> +++++++++++++++++++++++++++++++++


You could try this script:
sServerList = "d:\temp\Servers.txt"
sOutputFolder = "d:\temp\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oServerList = oFSO.OpenTextFile(sServerList)
While Not oServerList.AtEndOfStream
ProcessServer(oServerList.ReadLine)
Wend
oServerList.Close

Sub ProcessServer (sServer)
Set oOutputFile = oFSO.CreateTextFile(sOutputFolder & sServer)
Set objWMIService = GetObject("winmgmts:\\" & sServer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_ComputerSystem")
For Each objItem In colItems
oOutputFile.WriteLine "Server name: " & sServer
oOutputFile.WriteLine "Current Time Zone (Hours Offset From GMT): " &
(objItem.CurrentTimeZone / 60)
oOutputFile.WriteLine "Daylight Saving In Effect: " &
objItem.DaylightInEffect
Next
oOutputFile.Close
End Sub


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      09-26-2008

"Stuart" <> wrote in message
news:b3a64397-2bf1-4470-94be-...
> The following will write what i want to a text file.... I just need to
> combine this with the "server lookup" list mention earlier.
>
> Any help would be greatly appreciated.
>
> Thanks,
> Stuart.
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++
> Dim oFilesys, oFiletxt, sFilename, sPath
>
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root
> \cimv2")
>
> Set objNet = CreateObject("WScript.NetWork")
> Set objComputer = CreateObject("Shell.LocalMachine")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Set oFilesys = CreateObject("Scripting.FileSystemObject")
> Set oFiletxt = oFilesys.CreateTextFile("C:\DST\server_dst.log", True)
> sPath = oFilesys.GetAbsolutePathName("C:\DST\server_dst.lo g")
> sFilename = oFilesys.GetFileName(sPath)
> Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
>
> For Each objItem in colItems
> oFiletxt.WriteLine "Daylight Day - " & objItem.DaylightDay & "
> Daylight Day of Week - " & objItem.DaylightDayOfWeek & " Daylight
> Month - " & objItem.DaylightMonth
> Next
>
> oFiletxt.Close'
>


I could give you a turn-key solution but I feel that you would derive a much
greater benefit if I held your hand so that you can take few steps that
remain to reach your goal. Let me ask you a few questions about your code:
- Where is the output supposed to be written to? To a single file? To
different files, one for each server?
- Where do you define the name of the computer you're interrogating?
- What happens when you replace the current name with a different name and
run the program?
- What happens when you structure your program like so:

Dim oFilesys, oFiletxt, sFilename, sPath
strMachine = "."
ProcessServer strMachine

Sub ProcessServer(strComputer)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set objNet = CreateObject("WScript.NetWork")
Set objComputer = CreateObject("Shell.LocalMachine")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oFiletxt = oFilesys.CreateTextFile("C:\DST\server_dst.log", True)
sPath = oFilesys.GetAbsolutePathName("C:\DST\server_dst.lo g")
sFilename = oFilesys.GetFileName(sPath)
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")

For Each objItem in colItems
oFiletxt.WriteLine "Daylight Day - " & objItem.DaylightDay & "
Daylight Day of Week - " & objItem.DaylightDayOfWeek & " Daylight
Month - " & objItem.DaylightMonth
Next

oFiletxt.Close
end sub


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      09-29-2008
*** See below.

"Stuart" <> wrote in message
news:33617b4d-b13c-4fa7-83eb-...
Hiya, sorry for the delay... we just had our weekend here...

- Where is the output supposed to be written to? To a single file? To
different files, one for each server?

I would like to output to go to a single file, with a new line for
each server name, and example being as follows...
our-server01 Daylight Day - 1 Daylight Day of Week - 0 Daylight Month - 10

*** You could use wscript.echo and capture the text at
*** the operating system level by redirection:
*** cscript.exe c:\MyScript.vbs >> c:\MyScript.log

- Where do you define the name of the computer you're interrogating?

I have a txt file (called servers.txt) within the same folder,
servers.txt contains a pre-complied list of server names such as
this...
our-server01
our-server02
our-server03

- What happens when you replace the current name with a different name
and run the program?
If server_dst.log doesn’t exist, it is created.... if it does exist,
the data is just over written... so I need to append to this file..

- What happens when you structure your program like so?
It works fine, it outputs the information I need to a text file called
server_dst.log, the exact output is as follows...
Daylight Day - 1 Daylight Day of Week - 0 Daylight Month - 10

Daylight Day - 1 - Means first occurrence of the selected day within
the month
Daylight Day of Week - 0 - Means the selected day of the month (zero
being Sunday)
Daylight Month - 10 - Means which month of the year

So, this part works exactly as needed besides the need to append the
output... The bit I am not sure about is how to combine this with the
"Get the server names from this file" part.... and also append the
server name to the beginning of the output line.

Best regards,
Stuart.

***********
I gave you the full answer in my first reply in this thread. Here it is
again. The code reads one line at a time from your server list, then
invokes the subroutine (which you say you have tried yourself).

sServerList = "d:\temp\Servers.txt"
sOutputFolder = "d:\temp\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oServerList = oFSO.OpenTextFile(sServerList)
While Not oServerList.AtEndOfStream
ProcessServer(oServerList.ReadLine)
Wend
oServerList.Close


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      09-29-2008

"Stuart" <> wrote in message
news:cb11b59f-9f51-43a4-8f85-...
> I gave you the full answer in my first reply in this thread. Here it is
> again. The code reads one line at a time from your server list, then
> invokes the subroutine (which you say you have tried yourself).
>
> sServerList = "d:\temp\Servers.txt"
> sOutputFolder = "d:\temp\"
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oServerList = oFSO.OpenTextFile(sServerList)
> While Not oServerList.AtEndOfStream
> ProcessServer(oServerList.ReadLine)
> Wend
> oServerList.Close


Hiya,

Yep, I have tried placing the sServerList section directly above the
subroutine, but it just doesn't work... I should mention that on a
scale of 1 to 100, by vbs skills are about 3... as in I can read
English but that is about it.... when i run them combined, I get 1
line of subroutine output (no server name is included and there is no
second line from the second server is the server.txt file)... also, do
I need to include an append command somewhere?

Thanks,
Stuart.

============

Let's have a look at your script.


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      09-30-2008

"Stuart" <> wrote in message
news:5486528d-4053-4c3e-9230-...
> Do you happen to know of a good website for vbs beginners?


As a beginner you would benefit greatly if you studied an code example that
did more or less what you want. The code I gave you right at the start of
this thread would have been an excellent example - it came within 99% of
your requirements. It seems you were reluctant to take up this learning
opportunity, so here is the code. If you want to find out more about VB
Scripting, check the questions and responses in
microsoft.public.scripting.vbscript. This will be a harder path to follow
because you will have to sift through many posts before you find something
that relates to whatever problem you happen to have at hand.

sServerList = "d:\temp\Servers.txt"
sOutputList = "d:\temp\Daylight.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oServerList = oFSO.OpenTextFile(sServerList)
Set oOutputFile = oFSO.CreateTextFile(sOutputList)
While Not oServerList.AtEndOfStream
ProcessServer(oServerList.ReadLine)
Wend
oOutputFile.Close
oServerList.Close

Sub ProcessServer (sServer)
Set objWMIService = GetObject("winmgmts:\\" & sServer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem In colItems
oOutputFile.WriteLine "Daylight Day - " & objItem.DaylightDay _
& " Daylight Day of Week - " & objItem.DaylightDayOfWeek _
& " Daylight Month - " & objItem.DaylightMonth
Next
End Sub


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      10-01-2008
Why not set sOutputList=c:\dst\Daylight.csv straight away instead of
renaming it later on?

When you have a little more experience then might consider writing your data
directly into a spreadsheet instead of creating a CSV file. The statement
Set oExcel = CreateObject ("Excel.Application") will let you create a
suitable object for this purpose.


"Stuart" <> wrote in message
news:0355f988-fc23-435b-861a-...
> Okay, I have played around a bit more and have ended up with what I
> wanted...
>
> Once the script has completed, rename the Daylight.txt to Daylight.csv
> and it will show up in Excel in a usable format.
>
> Thanks Pegasus, I really do appreciate your help.
>
> Best regards,
> Stuart.
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++
> sServerList = "c:\dst\Servers.txt"
> sOutputList = "c:\dst\Daylight.txt"
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oServerList = oFSO.OpenTextFile(sServerList)
> Set oOutputFile = oFSO.CreateTextFile(sOutputList)
> While Not oServerList.AtEndOfStream
> ProcessServer(oServerList.ReadLine)
> Wend
> wscript.echo "finished"
> oOutputFile.Close
> oServerList.Close
> Sub ProcessServer (sServer)
> Set objWMIService = GetObject("winmgmts:\\" & sServer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery("Select * from
> Win32_TimeZone")
> Set colSettings = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
> For Each objComputer in colSettings
> TXT = "System Name: " & objComputer.Name
> Next
> Set objWMIService = GetObject("winmgmts:\\" & sServer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery("Select * from
> Win32_TimeZone")
> For Each objItem In colItems
> txt = txt & "," & "Daylight Day - " & objItem.DaylightDay &
> ",Daylight Day of Week - " & objItem.DaylightDayOfWeek & ", Daylight
> Month - " & objItem.DaylightMonth
> oOutputFile.WriteLine txt
> Next
> End Sub
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Daylight Saving time Lino767 Windows Server 3 10-30-2007 02:07 PM
Daylight Saving Time changes Don Devenney Windows Server 2 10-20-2007 04:33 PM
Daylight Saving Time qq Windows Server 4 02-22-2007 01:33 PM
Daylight Saving Time luv2bike2 Windows Update 5 02-14-2007 12:48 AM
Daylight Saving time? Andrew Windows Server 2 03-23-2005 04:10 PM



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 47 48 49 50 51 52 53 54 55 56 57 58 59