Thursday, September 29, 2005

Showing status of all SMTP Virtual Servers in your domain

The status of your SMTP virtual servers eg whether the server is Started, Stopped, Paused is held in the IIS Metabase on your Exchange server in the ServerState property. If you wanted to query this value from a script there is a ADSI provider for IIS which allows you to connect to the Metabase and retrieve this value much like you can with Active Directory.

Armed with this information you can now create a script that first queries Active Directory for all the Virtual Server objects within a domain. Then using the properties on these Virtual server object you can determine the servername of each server where the VS exists and then connect to the Metabase on that server and retrieve the Serverstate property. So you end up with a simple script that will give you a status of all the SMTP virtual servers in you AD domain. This script looks like the following I’ve put a downloadable copy here

set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
Com.ActiveConnection = Conn
Com.ActiveConnection = Conn
Wscript.echo "SMTP Virtual Servers Status"
vsQuery = "<LDAP://" & strNameingContext & ">;(objectCategory=protocolCfgSMTPServer);name,distinguishedName;subtree"
Com.ActiveConnection = Conn
Com.CommandText = vsQuery
Set Rs = Com.Execute
While Not Rs.EOF
strstmsrv = "LDAP://" & rs.fields("distinguishedName")
set svsSmtpserver = getobject(strstmsrv)
wscript.echo "ServerName:" &

sub getSTMPstatus(servername,vsname)
Set SMTPVSS = GetObject("IIS://" & Servername & "/SMTPSVC")
for each SMTPVS in SMTPVSS
if SMTPVS.KeyType = "IIsSmtpServer" then
if SMTPVS.ServerComment = vsname then
wscript.echo "SMTP Server : " & SMTPVS.ServerComment
select case SMTPVS.ServerState
case 1 Wscript.echo "Current State: Starting"
case 2 Wscript.echo "Current State: Started"
case 3 Wscript.echo "Current State: Stopping"
case 4 Wscript.echo "Current State: Stopped"
case 5 Wscript.echo "Current State: Pausing"
case 6 Wscript.echo "Current State: Paused"
case 7 Wscript.echo "Current State: Continuing"
case else Wscript.echo "unknown"
end select
end if
end if

end sub


Anonymous said...

Is there any way to use this same script for POP3 virtual setting? I tried using protocolCfgPOPServer but get nothing back.


Glen said...

You need to use msExchprotocolCfgPOPSessions instead.