Si está utilizando .NET 3.5 o posterior, puede utilizar un PrincipalSearcher
y un director "de consulta por ejemplo" para hacer su búsqueda:
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// define a "query-by-example" principal - here, we search for a UserPrincipal
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.SamAccountName = "Esteban*";
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach(var found in srch.FindAll())
{
// do whatever here - "found" is of type "Principal" - it could be user, group, computer.....
}
Si usted no ha Ya lo hizo, lea absolutamente el artículo de MSDN Managing Directory Security Principals in the .NET Framework 3.5 que muestra muy bien cómo hacer el mejor uso de las nuevas funciones en System.DirectoryServices.AccountManagement
. O vea el espacio de nombre MSDN documentation on the System.DirectoryServices.AccountManagement.
Por supuesto, dependiendo de sus necesidades, es posible que desee especificar otras propiedades en ese principal "de consulta por ejemplo" usuario se crea:
DisplayName
(normalmente: nombre + espacio + apellido)
SAM Account Name
- su/AD nombre de cuenta de Windows
User Principal Name
- su "[email protected]" nombre de estilo
puede SPE cifique cualquiera de las propiedades en el UserPrincipal
y utilícelas como "consulta por ejemplo" para su PrincipalSearcher
.
Solo estoy manteniendo algún código existente, así que no quiero estropear mucho con el código que me enviaste, sin embargo con esto supongo que puedo poner * al principio y al final y debería funcionar también. –
así: sAMAccountName = * "+ sAMAccountName +" *) –
@EstebanV .: [de acuerdo con esto] (http://technet.microsoft.com/en-us/library/ee198823.aspx) parece que debería funcionar Sí, –