PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Daylight savings script - to confirm current status
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Daylight savings script - to confirm current status

Réponse
 
LinkBack Outils de la discussion
Vieux 24/09/2008, 09h40   #1
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Daylight savings script - to confirm current status

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 ..

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
+++++++++++++++++++++++++++++++++
  Réponse avec citation
Vieux 24/09/2008, 09h58   #2
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight savings script - to confirm current status

Actually... just to clarify a little...

I need to confirm that all our servers have had the following patch
applied.. this is due to changed DST dates here in Australia.

http://support.microsoft.com/kb/942763

Thanks,
Stuart.



  Réponse avec citation
Vieux 24/09/2008, 10h34   #3
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status


"Stuart" <stuart.angus@gmail.com> wrote in message
news:b60fa100-9679-426e-bf1b-8d5fa2e1c63e@m45g2000hsb.googlegroups.com...
> 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 ..
>
> 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


  Réponse avec citation
Vieux 26/09/2008, 04h25   #4
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

Could you run your eyes over this please? I am trying to use bits and
pieces from different scripts to make this work...

Wish I knew what I was doing...

+++++++++++++++++++++++++++++++++++++++++
Dim objNet

On error resume next

Const ForAppending = 8

sServerList = "C:\DST\Servers.txt"
sOutputFolder = "C:\DST"

Set objNet = CreateObject("WScript.NetWork")
Set objComputer = CreateObject("Shell.LocalMachine")
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 = oFileSYS.CreateTextFile("C:\DST\server_dst.log",
ForAppending, True)
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 "Daylight Day: " & objItem.DaylightDay
oOutputFile.WriteLine "Daylight Day of Week: " &
objItem.DaylightDayOfWeek
oOutputFile.WriteLine "Daylight Month: " & objItem.DaylightMonth
Next
oOutputFile.Close
End Sub



  Réponse avec citation
Vieux 26/09/2008, 07h55   #5
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

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 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'

  Réponse avec citation
Vieux 26/09/2008, 15h09   #6
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status


"Stuart" <stuart.angus@gmail.com> wrote in message
news:b3a64397-2bf1-4470-94be-a83e23493f0e@73g2000hsx.googlegroups.com...
> 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 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


  Réponse avec citation
Vieux 29/09/2008, 08h09   #7
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

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

- 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.

  Réponse avec citation
Vieux 29/09/2008, 11h19   #8
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

*** See below.

"Stuart" <stuart.angus@gmail.com> wrote in message
news:33617b4d-b13c-4fa7-83eb-5e39c769ed49@q9g2000hsb.googlegroups.com...
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


  Réponse avec citation
Vieux 30/09/2008, 00h54   #9
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

> 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.
  Réponse avec citation
Vieux 30/09/2008, 01h27   #10
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status


"Stuart" <stuart.angus@gmail.com> wrote in message
news:cb11b59f-9f51-43a4-8f85-a07216b8c319@q9g2000hsb.googlegroups.com...
> 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.


  Réponse avec citation
Vieux 30/09/2008, 01h57   #11
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

Do you happen to know of a good website for vbs beginners?

  Réponse avec citation
Vieux 30/09/2008, 18h05   #12
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status


"Stuart" <stuart.angus@gmail.com> wrote in message
news:5486528d-4053-4c3e-9230-78b83b6c8910@y21g2000hsf.googlegroups.com...
> 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


  Réponse avec citation
Vieux 01/10/2008, 04h34   #13
Stuart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

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 .

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
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++

  Réponse avec citation
Vieux 01/10/2008, 08h55   #14
Pegasus \(MVP\)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Daylight saving time script - to confirm current status

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" <stuart.angus@gmail.com> wrote in message
news:0355f988-fc23-435b-861a-c8a95b0dc1ca@2g2000hsn.googlegroups.com...
> 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 .
>
> 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
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++
>



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h31.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28355 seconds with 22 queries