I want my DirectoryEntry methods back

RC2 is out and we have a new type alias [ADSI] for dealing with DirectoryEntry objects in AD, but inexplicably (at least to me), we’ve lost all the methods associated with that class unless you change everything to use psbase

So instead of saying something like

PS>$Entry = New-Object DirectoryServices.DirectoryEntry (“LDAP://dc=domain,dc=com”)

I can say

PS>$Entry = [ADSI] “LDAP://dc=domain,dc=com”

But instead of saying


I have to say


And a fair amount of working code no longer works.

I don’t pretend to understand the discussion on the newsgroup about “adapting” and why using psbase is better than before. So in the spirit of PowerShell, I’ve just extended the type definition for DirectoryEntry so that I can still use the previous code.

For each of the previous methods for DirectoryEntry, I’ve added a ScriptMethod. So for example,


allows me to continue to use


without the psbase “layer”.

This also allows previous code like MoW’s


to work again. I haven’t tested these definitions thoroughly so YMMV, but if you’d like to try them out, please help yourself to a copy of them. Comments are always welcome also.


One response to “I want my DirectoryEntry methods back

  1. justanothersysadmin


    I had not really gotten into ScriptMethods, but your last few posts have really shown their usefulness. The whole “psbase” is also a bit over my head (although I have seen some posts from the PS development guys that they might have made a mistake in releasin V1 that way), so this is definitely a neat trick around it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s