Windows

Setting up Sysprep for vCenter 2.5

Several of my recent clients (my current one included) have both avoided, failed or just not used Virtual Machine (VM) templates. Depending on who you ask the answer to the question “Why Not?” seems to vary between:

  • “I didn’t know that you could do that”
  • “We couldn’t make it work”
  • “It was too complicated to setup”
  • “We haven’t had the time yet”
  • “All of our new VMs are different”

After some convincing I have persuaded my current client to let me configure sysprep and a couple of templates for them. I’ve done this a few times before but never really documented it. Admitedly a lot of this is already documented in the Basic Admin Guide for vCenter but this post saves downloading a PDF file.

More >

Windows Server Versions (Requirements)

I often forget half of this stuff so I thought it might be cunning to put some of it into a post. Sorry if it goes on a bit, some of the numbers change depending on your choice of Service Pack and it was easier to split that sort of thing into separate tables. More >

Remote Shutdown with PowerShell

Here’s the scenario: You’ve just hit shut down in your remote desktop session. You’re logged off Windows Server 2003 and your RDP session is closed. You wait a while and try to login again. Surely the server must have rebooted by now. But try as you might, you cannot get back in. Port 3389 shows as open and the IP is pingable.

So the options are:

1. Dig out iLO credentials (assuming that it is installed / setup) and force a reboot from a remote console.

2. Walk over to the server and force a reboot (the most recent time this has happenned to me, the server was in another building and it was raining heavily).

3. Use conventional Windows management tools to shut the server down remotely.

4. Use PowerShell.

This last option is the one that we’re going to opt for. We’re going to use the Win32_OperatingSystem WMI class to do this. Specifically we’ll be using the Win32Shutdown method.

The method takes a single flag value to determine exactly what should be done.

0 = Log off
4 = Forced log off
1 = Shutdown
5 = Forced shutdown
2 = Reboot
6 = Forced reboot
8 = Power off
12 = Forced power off

The full code for invoking the method is:

(Get-WmiObject -Class Win32_OperatingSystem -ComputerName MyComputer).InvokeMethod("Win32Shutdown",0)

From now on I’ll use aliases. Here are a couple of examples:

Log off the local computer:

(gwmi Win32_OperatingSystem).Win32Shutdown(0)

Restart a remote computer:

(gwmi win32_operatingsystem -ComputerName MyComputer).Win32Shutdown(6)

Restart a remote computer using alternate credentials:

(gwmi win32_operatingsystem -ComputerName MyComputer -cred (get-credential)).Win32Shutdown(6)

Windows 2003 Cluster failover email

I’ve lost track of the number of clusters that I have implemented or supported over the last few years. With each edition of Windows server that comes out clustering has improved. It was a bit of a dark art with Windows 2000 and in Windows 2008 it’s pretty much all point and click (and not many clicks at that). Most clusters that I encounter at the moment are still 2003. In a lot of organisations the joys of 2008 are still to come.

Clustering in 2003 offers few built in options for notifying anybody that a resource group has moved or failed over to another node. Ideally, the fact that it has should not be any cause for alarm but there are occasions when it is useful to know. Fortunately for some a well trained piece of monitoring software running on your network can alert you to events as they unfold and allow you time to resolve any issues and move the resource group back. For others, they must either check manually on a regular basis or find out at some later time when something else goes wrong and can be traced back to the resource group moving. Examples of such problems that I have encountered include:

  • The local drive used for SQL database backups in a cluster running multiple instances not being big enough to cope with the backup files from both instances. If the two instances ended up on the same node then several scheduled tasks failed to complete.
  • Exchange 2003 backups that only worked from one node of a two node cluster.
  • Restrictive change control policies that required a restrospective change request to be raised within a number of hours or the world would end (really!)

In these instances I have found that a simple email notification can be quite handy. Sadly, Windows 2003 Clustering does not have such a facility. One can be created though.

I found the following script somewhere a few months ago that I have reused several times. It is a simple VBS script that, once customised slightly with correct values for your environment, is placed on every node in the cluster.

'Program Cluster Monitor
'Author: Pat Lee
'Date: 24 April 2008

'Program Description:
'This program runs as a generic cluster application.  When the cluster fails over/back it will send an email
'indicating the current owner.  Change the constants as appropriate for your environment.  It's advisable To
'send this email to a distribution group to facilitate administration of email.  Refer to:
'http://support.microsoft.com/kb/260527 for instructions on setting up the generic cluster app.

Const strMailFrom = "ClusterMonitor@mycompany.com"
Const strMailTo = "ClusterDistributionGroup@mycompany.com"
Const strMailSubject = "Node moved to: "
Const strMailBody = "Mailbody"
Const strMailServer = "myExchangeServer.myCompany.com"

Dim strNodeName
Dim wshNetwork
Dim strNodeSubject

Set WshNetwork = WScript.CreateObject("WScript.Network")
strNodeName = WshNetwork.ComputerName 

strNodeSubject = strMailSubject & " " & strNodeName & " @ " & Now()

sendEmail strMailFrom, strMailTo, strNodeSubject, strMailBody, strMailServer

Sub sendEmail(mailFrom, mailTo, mailSubject, mailBody, mailServer)
    Dim objEmail
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = mailFrom
    objEmail.To = mailTo
    objEmail.Subject = mailSubject
    objEmail.Textbody = mailBody
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'careful on this one - use a parameter rather than a global for mailserver
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailServer
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update

    On Error Resume Next
    objEmail.Send
    If Err.Number <> 0 Then
        Call logMessage(3, "Error sending mail - " & Err.Number & " " & Err.Description)
        Err.Clear
        On Error GoTo 0
    End If

    Set objEmail = Nothing
End Sub

The other component that is required is a single line batch file on each node that calls the VBS file above.

wscript c:\pathtovbsfile\vbsfile.vbs

Finally, a resource needs to be added to the resource group that you want to be alerted about using the instructions in this Microsoft KB article.