Powershell: Quick script to email DST status

Described by some as "another Y2K", DST in North America started 3 weeks earlier.  Unfortunately, I never got to post this in timefor the changeover, but DST will end 1 week later, so we’re not done testing.

Here’s a Powershell script that gets DST status and mails it to the address specified in the command line.  It’s great boilerplate code if you need to send a quick status email and much much better than the old way with NT CMD, Blat and VBScript.

 


# Send-DSTStatus
#
# Get current time and DST status of specified computer and email to specified user
# For use in supporting North American DST changes
#
# D. Moisan 2/23/2007
#
param([string]$computer, [string]$email)
#
# Parameters (Required):
#
# -computer <computer to scan for status>
# -email <email address>

if ($email -eq "") {
   write-host "Usage:"
   write-host
   write-host "send-DSTStatus [-computer <computer>] -email <somebody@somewhere.com>"
   write-host
   write-host "`t-computer defaults to local machine if not specified"
   write-host
   exit
   }

#
# Set up email sender address and server name
#
$sender = "Administrator@satvonline.org"  # Change as needed
$mailservername = "salemtv.satv.loc"    # Change to your SMTP server's address

$mailserver = new-object system.net.mail.smtpClient
$mailserver.Host = $mailservername
$mailmessage = new-object system.net.mail.mailmessage($sender,$email)

# If -computer parameter not specified, use localhost

if ($computer -eq "") {
   $computer = $Env:Computername
   }

# Get WMI Objects

$wmios = get-wmiobject "Win32_OperatingSystem" -computer $computer
$wmisys = get-wmiobject "Win32_ComputerSystem" -computer $computer

# Compose message

$maildate = get-date
$mailmessage.Subject = "DST Status Report for $computer on $maildate"
$mailmessage.Sender = $sender
$messagetext = $mailmessage.Subject + "`n`n"
$messagetext += "Local Time for $computer : " + $wmios.ConverttoDateTime($wmios.LocalDateTime) + "`n`n"
$DSTEnabled = $wmisys.EnableDaylightSavingsTime
$DSTInEffect = $wmisys.DaylightInEffect
$TZOffset = $wmisys.CurrentTimeZone
if ($DSTEnabled) {
   $messagetext += "DST is ENABLED`n" }
else {

   # We can't tell if Windows 2000 clients have DST implemented since
   # the WMI property EnableDaylightSavingsTime is not supported there
   # so if the property is null (as is the case in 2000), we skip reporting
   # DST enabled.  IF it is False (as in an XP/2003 client with DST turned off),
   # we report that.

   if ($DSTEnabled -eq $False) {
      $messagetext += "DST is NOT ENABLED`n"
      }
   }

if ($DSTInEffect) {
   $messagetext += "DST is IN EFFECT`n" }
else {
   $messagetext += "DST is NOT IN EFFECT`n" }

$messagetext += "Current timezone offset: $TZOffset `n"
$messagetext += "`n`n"

# Send mail and report it on the console

$mailmessage.Body = $messagetext
write-host "From: $sender"
write-host
write-host "To: $email"
write-host
write-host $messagetext
$mailserver.Send($mailmessage)

Wow, the regression testing for Windows Server 2003 SP2 is *really* thorough!

 

I saw this KB, Windows Server 2003 Service Pack 2 application compatibility, and noted this program tested:

Vendor        Application name   Version

3D Realms   Duke Nukem 3D    1

*snort!*

Gee, do you think Duke Nukem Forever will work on Longhorn Server?


Windows Server 2003 SP2 Quirk: Exchange doesn’t start

Windows Server 2003 Service Pack 2 is out.  As usual, my home SBS box took it without problems, but not our SBS server at the studio.  After a protracted install (over an hour!),  I rebooted and Exchange Information Store did not start.  I started it manually and it came up.   Further analysis got me these two event log entries:
 
Event Type: Error
Event Source: DCOM
Event ID: 10010
Date:  3/14/2007
Time:  9:48:51 PM
Computer: [...]
Description:
The server {9DA0E106-86CE-11D1-8699-00C04FB98036} did not register with DCOM within the required timeout.
 
[And then this...]
 
Event Type: Error
Event Source: Service Control Manager
Event ID: 7024
Date:  3/14/2007
Time:  9:48:56 PM

Computer: [...]
Description:
The Microsoft Exchange Information Store service terminated with service-specific error 2147500037 (0×80004005).

 
 
The server cited in the DCOM message is the Microsoft Exchange Property Mapping Interface.  Exchange has new and interesting dependencies every day!
 
Exchange started on the next reboot when I reinstalled IE7, so this is probably transient.  Just so you know.
 
Susan Bradley has more to say on SP2.

Follow

Get every new post delivered to your Inbox.