Video Screencast Help
Search Video Help Close Back
to help
Not able to make it to Vision this year? Get a sampling in the Best of Vision on Demand group.

Changing the Time Zone Using DS, a Custom Token and an External Database!

Updated: 05 May 2008
Matt S's picture
0 0 Votes
Login to vote

This is a great way to further optimize your 'post deployment' configuration of machines.

With several locations across the country, I needed a way to set our time zones automatically as we roll out machines.

Things this assumes:

  1. All machines names start with a 4 character location code(you could easily manipulate things for other scenarios)
  2. External SQL database that has both the location and the time zone of that device..
  3. Deployment server!

Hopefully you find this as helpful!

Step 1.

Go to Tools -> Options in Deployment server, in the Custom Data Sources tab, add the appropriate info to log into the External Database.

In my case, I called the data source 'TZ'. The Database that TZ points to has a table called Locations which contains 2 fields. Location_ID and TimeZone.

In my database, Location_ID is of type INT and thus the vbscript seen below does some manipulation in the query.(Casts the left 4 characters of %NAME% as INT in the query) TimeZone has the 3 character timezone of the device. So when the query is executed, it returns the 3 character timezone.

Step 2.

Create a DS job that is a 'run script' and then use the below script:

'vbscript Automatic TimeZone
Dim strTZ,nRtn

strTZ = "%#TZ*"select TimeZone from Locations where Location_ID like CAST (left('%NAME%',4) AS INTEGER)%"

Select Case strTZ
      Case "PST" strTimeZone = "(GMT-08:00) Pacific Time (US & Canada)"
      Case "AST" strTimeZone = "(GMT-07:00) Arizona"
      Case "MST" strTimeZone = "(GMT-07:00) Mountain Time (US & Canada)"
      Case "CST" strTimeZone = "(GMT-06:00) Central Time (US & Canada)"
      Case "EST" strTimeZone = "(GMT-05:00) Eastern Time (US & Canada)"
End Select  

nRtn = SetTimeZone(strTimeZone)

Function SetTimeZone(strZone)
  Dim strCommand
  Dim errReturn
  Dim oShell
  Set oShell = CreateObject ("Wscript.shell")
  strCommand = "c:\windows\system32\Control.exe TIMEDATE.CPL,,/Z " & strZone
  errReturn = oShell.run (strCommand,1,True)
  Set oShell = Nothing
End Function