Thursday, July 29, 2004

Disabling and Enabling POP3 and IMAP protocol settings via ADSI

  When you install Exchange and create all your mailboxes by default every mailbox will have POP3,IMAP and HTTP protocols enabled. Good practice is if you don't want people to use these protocols is just disable the protocols on the server which makes the user account settings redundant. But this is not always possible and sometimes you need to leave POP3 and IMAP access enabled for some applications or clients. So to stop people using POP3 and IMAP it can be a good idea to disable that protocol on their Active Directory user account.

  To do this via ADSI is not that hard if you keep the following things in mind. The property that controls both these setting is the protocolSettings attribute of the User object. This is a mutli-valued property which also holds the setting for HTTP (OWA Access) as well.  By default this property will be blank meaning everything is enabled. Once you disable a protocol a value will get written for that protocol into the property. If you then re-enable the protocol this entry is not deleted rather one bit in the existing property is flipped. For example when I disable IMAP the following gets written into this property.

IMAP4§0§1§4§ISO-8859-1§0§1§0§0  (note because I'm an Aussie we use ISO character sets)

When you re-enable IMAP it just flips the first bit after the protocol IMAP4§0 from 0 to 1 eg

IMAP4§1§1§4§ISO-8859-1§0§1§0§0

So armed with this information to disable pop3 and imap on a mailbox with ADSI, (taking into account nothing has been set for HTTP because this will overwrite that property) you could use the following code (make sure you change the character set to whatever you use)

qstring = "LDAP://CN=USER,OU=wherver,DC=domain,DC=com"
set objUser = GetObject(qstring)
objUser.PutEx 2, "protocolSettings",ARRAY("POP3§0§1§4§ISO-8859-1§0§§§","IMAP4§0§1§4§ISO-8859-1§0§1§0§0")
objUser.setinfo
 
Flipping it back is a matter of using the same code with the reverse bits

qstring = "LDAP://CN=USER,OU=wherver,DC=domain,DC=com"
set objUser = GetObject(qstring)
objUser.PutEx 2, "protocolSettings",ARRAY("POP3§1§1§4§ISO-8859-1§0§§§","IMAP4§1§1§4§ISO-8859-1§0§1§0§0")
objUser.setinfo



5 comments:

Anonymous said...

Wonderfull, just what I needed.

Thanks, Eric S

Frank Carius said...

Only an addition
I wrote a simialr script some month ago dong the same.
Buti use the group membership to control the permissions and create a XML/XSL-Output, so you can also see the current settings and changed settings.
http://www.msxfaq.de/tools/grp2exinet.htm

unfortunaly the web and description is german. maybe google can help. But its only vbscript, so no problem to read the code.

Frank

Glen said...

Thanks for sharing Frank

Cheers
Glen

Term paper said...

Thanks for sharing. i really admire this.

William Olson said...

Glen, I realize this is an old post for you, but I am looking to do what you listed here for Exchange 2007. I don't want to use a powershell script. Do you have an updated verison of this to disable OWA?
William
william@e-olsons.com