“Let’s do the Time Zone Again…”
I’ve gotten a number of inquiries about the VBScript I wrote for checking time zone settings. Now that it’s getting closer to Standard Time people are getting jumpy again. New servers have been added to the data center over the last few months; are the DST settings correct? Instead of sharing the VBScript code, let’s do this in PowerShell…
First, here is a simple command you can run to check the current Daylight Savings Time on a computer:
Time Zone Settings
A properly configured DST setting should yield the results above. With the exception of Time Zone, mine happens to be Pacific Standard Time. There are two sets of properties; “Daylight” are the settings for when Daylight Savings starts, “Standard” for when it ends.
So what do these properties and numbers all mean:
- DaylightDay : 2 = This indicates the second occurrence of a particular day within a month.
- DaylightDayOfWeek : 0 = Indicates the day assigned is Sunday. 1 = Monday and so on…
- DaylightHour : 2 = 02:00 AM.
- DaylightMonth : 3 = Indicates the Month of March.
According to the “Daylight” settings, this computer is configured to change time on the Second Sunday of March at 02:00 AM, just what we want to see.
- StandardDay : 1 = Indicates the fist occurrence of a particular day within a month.
- StandardDayOfWeek : 0 = Again, Sunday is the day.
- StandardHour : 2 = 02:00 AM.
- StandardMonth : 11 = November.
The computer is configured to end Daylight Savings Time and return to Standard Time on the First Sunday of November at 02:00 AM. So I’m covered.
Let’s use the same cmdlet and gather the DST information from a remote computer:
You may notice that I changed the “Format-List” command. Before I used a regular expression “[a-z]*” which pulled all the property names that start with any alpha character. In the command above, I used “Format-List *” to gather all entries for the class. I did this because I am interested in the “__SERVER” entry. Knowing which computer is sending information is vital as I’ll show you in the next example.
Using an Array to Enumerate Multiple Remote Computers
Connecting to multiple computers. Enter the computer names you wish to enumerate.
Using an array, in this fashion, is OK if you have a small environment and/or just checking a few machines. What if you have hundreds of computers? Time to script it. If you have read any of my other articles, you know that I like to keep a list of computer names in a text file and build an array using the list.
Step 1. Create a text file called “Computers.txt” and store it on the computer that will run the script. For this example, let’s store the file on the root of C: Drive. The text file should look similar to this, with each computer name on it’s own line.
Enter Computer Names
Step 2. Write a PowerShell script that imports each computer name into an array and enumerates the TimeZone settings of each computer. You can copy and past the script code (below) directly into the PowerShell Command Shell. If you prefer, you can copy the code into a .ps1 PowerShell Script file and run the script from the command prompt.
ForEach($strComputer in $arrComputers)
{
get-wmiobject -Class “win32_TimeZone” -namespace “root\CIMV2″`
-computername $strComputer | Format-List *
}
Error codes(script debugging) can be added, but if a computer is off-line or doesn’t exist, PowerShell will report any errors in the console, and then continue running until it reaches the end of the script.
Let’s create a report by exporting the output into a .txt file.
ForEach($strComputer in $arrComputers)
{
get-wmiobject -Class “win32_TimeZone” -namespace “root\CIMV2″`
-computername $strComputer | Format-List * | Out-File -Append “C:\DSTListReport.txt”
}
Open the Text file using the “Invoke-Item” cmdlet.
The DSTListReport.txt file will contain information from only the computers the script was able to communicate with. Let’s create another report, this time let’s put it in a table format. I’m also going to limit the table entries to list only the properties I require for the report.
ForEach($strComputer in $arrComputers)
{
get-wmiobject -Class “win32_TimeZone” -namespace “root\CIMV2″`
-computername $strComputer | Format-Table -Wrap -Property __SERVER,DaylightDay,`
DaylightDayOfWeek,DaylightHour,DaylightMonth,StandardDay,StandardDayOfWeek,`
StandardHour,StandardMonth | Out-File -Append “C:\DSTTableReport.txt”
}
Open the Text file using the “Invoke-Item” cmdlet.
So, the question is what to do if you find a computer that doesn’t have the proper DST settings? Microsoft has created some new utilities that should work better than the ones available last spring. The tools are located here: August 2007 cumulative time zone update for Microsoft Windows operating systems. Also, be aware that there have been some modifications to the Time Zone registry settings since last spring. Read “How to configure daylight savings time…”
My Advice would be to re-run the examples above after you have updated DST Settings. It’s important to verify that the change actually took place.
Email This Post To A Friend
« We Don’t Need No Stinkin’ Scripts… | Home | Download PowerShell 2.0 Community Technology Preview (CTP) »






Comments
i want a powershell script to create a new text file on any given drive and input some text into that
Leave a Comment