Skip to content

Instantly share code, notes, and snippets.

@evilz
Last active Aug 29, 2015
Embed
What would you like to do?
Active Directory Entity classes
using System.DirectoryServices;
namespace ActiveDirectory.Model
{
[DirectorySchema("group")]
public class ADGroup : DirectoryEntity , IDirectoryEntity
{
[DirectoryAttribute("name")]
public string name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
OnPropertyChanged("name");
}
}
}
private string _name;
[DirectoryAttribute("member")]
public string[] member
{
get { return _member; }
set
{
if (_member != value)
{
_member = value;
OnPropertyChanged("member");
}
}
}
private string[] _member;
[DirectoryAttribute("distinguishedName")]
public string distinguishedName
{
get { return _distinguishedName; }
set
{
if (_distinguishedName != value)
{
_distinguishedName = value;
OnPropertyChanged("distinguishedName");
}
}
}
private string _distinguishedName;
[DirectoryAttribute("mail")]
public string mail
{
get { return _mail; }
set
{
if (_mail != value)
{
_mail = value;
OnPropertyChanged("mail");
}
}
}
private string _mail;
[DirectoryAttribute("msExchRequireAuthToSendTo")]
public bool msExchRequireAuthToSendTo
{
get { return _msExchRequireAuthToSendTo; }
set
{
if (_msExchRequireAuthToSendTo != value)
{
_msExchRequireAuthToSendTo = value;
OnPropertyChanged("msExchRequireAuthToSendTo");
}
}
}
private bool _msExchRequireAuthToSendTo;
[DirectoryAttribute("description")]
public string description
{
get { return _description; }
set
{
if (_description != value)
{
_description = value;
OnPropertyChanged("description");
}
}
}
private string _description;
[DirectoryAttribute("displayName")]
public string displayName
{
get { return _displayName; }
set
{
if (_displayName != value)
{
_displayName = value;
OnPropertyChanged("displayName");
}
}
}
private string _displayName;
[DirectoryAttribute("groupType")]
public int groupType
{
get { return _groupType; }
set
{
if (_groupType != value)
{
_groupType = value;
OnPropertyChanged("groupType");
}
}
}
private int _groupType;
[DirectoryAttribute("memberOf")]
public string[] memberOf
{
get { return _memberOf; }
set
{
if (_memberOf != value)
{
_memberOf = value;
OnPropertyChanged("memberOf");
}
}
}
private string[] _memberOf;
[DirectoryAttribute("cn")]
public string cn
{
get { return _cn; }
set
{
if (_cn != value)
{
_cn = value;
OnPropertyChanged("cn");
}
}
}
private string _cn;
[DirectoryAttribute("managedBy")]
public string managedBy
{
get { return _managedBy; }
set
{
if (_managedBy != value)
{
_managedBy = value;
OnPropertyChanged("managedBy");
}
}
}
private string _managedBy;
[DirectoryAttribute("sAMAccountName")]
public string sAMAccountName
{
get { return _sAMAccountName; }
set
{
if (_sAMAccountName != value)
{
_sAMAccountName = value;
OnPropertyChanged("sAMAccountName");
}
}
}
private string _sAMAccountName;
public void AddMember(string memberDn)
{
DirectoryEntry.Properties["member"].Add(memberDn);
}
public void AddMembers(string[] memberDn)
{
foreach (string s in memberDn)
{
AddMember(s);
}
}
public void RemoveMember(string memberDn)
{
DirectoryEntry.Properties["member"].Remove(memberDn);
}
public void RemoveMembers(string[] memberDn)
{
foreach (string s in memberDn)
{
RemoveMember(s);
}
}
public void Create(string root)
{
DirectoryEntry rootDirectoryEntry = Helper.GetDirectoryEntry(root);
DirectoryEntry = rootDirectoryEntry.Children.Add("CN=" + this.cn, "group");
DirectoryEntry.Properties["SAMAccountName"].Add(this.sAMAccountName);
DirectoryEntry.Properties["groupType"].Add(this.groupType);
DirectoryEntry.CommitChanges();
}
public void Delete()
{
DirectoryEntry.DeleteTree();
DirectoryEntry.Close();
}
}
}
using System;
using System.DirectoryServices;
using ActiveDs;
using Spie.Provisioning.ActiveDirectory.Linq;
using System.Configuration;
namespace ActiveDirectory.Model
{
[DirectorySchema("user", typeof(IADsUser))]
public class ADUser : DirectoryEntity,IDirectoryEntity
{
/// <summary>
/// The scope of this attribute is specific to a single user or contact. The valid values (and associated bit positions) in Office Communications Server are as follows:
/// 0: Do not archive (no bit set)
/// 1: Retired (bit position 0)
/// 2: Retired (bit position 1)
/// 4: Archive internal communications (bit position 2)
/// 8: Archive federated communications (bit position 3)
/// </summary>
[DirectoryAttribute("msRTCSIP-ArchivingEnabled")]
public int? msRTCSIPArchivingEnabled
{
get { return _msRTCSIPArchivingEnabled; }
set
{
if (_msRTCSIPArchivingEnabled != value)
{
_msRTCSIPArchivingEnabled = value;
OnPropertyChanged("msRTCSIPArchivingEnabled");
}
}
}
private int? _msRTCSIPArchivingEnabled;
/// <summary>
/// This attribute specifies the different options that are enabled for the user or contact object. This attribute is a bit-mask value of type integer. Each option is represented by a bit. This attribute is marked for Global Catalog replication.
/// The valid value types are as follows:
/// 1: Enabled for public IM connectivity
/// 2: Reserved
/// 4: Reserved
/// 8: Reserved
/// 16: RCC (remote call control) Enabled [Telephony]
/// 64: AllowOrganizeMeetingWithAnonymousParticipants (allow users to invite anonymous users to meetings
/// 128: UCEnabled (enable users for unified communications)
/// 256: EnabledForEnhancedPresence (enable user for public IM connectivity)
/// 512: RemoteCallControlDualMode
/// 1024: Enabled auto-attendant (enables the use of auto attendant)
/// </summary>
[DirectoryAttribute("msRTCSIP-OptionFlags")]
public int? msRTCSIPOptionFlags
{
get { return _msRTCSIPOptionFlags; }
set
{
if (_msRTCSIPOptionFlags != value)
{
_msRTCSIPOptionFlags = value;
OnPropertyChanged("msRTCSIPOptionFlags");
}
}
}
private int? _msRTCSIPOptionFlags;
/// <summary>
/// Common name (Chaîne Unicode)
/// </summary>
[DirectoryAttribute("cn")]
public string cn
{
get { return _cn; }
set
{
if (_cn != value)
{
_cn = value;
OnPropertyChanged("cn");
}
}
}
private string _cn;
/// <summary>
/// Contains the name for the department in which the user works.
/// </summary>
[DirectoryAttribute("department")]
public string department
{
get { return _department; }
set
{
if (_department != value)
{
_department = value;
OnPropertyChanged("department");
}
}
}
private string _department;
/// <summary>
/// Contains the office location in the user's place of business.
/// </summary>
[DirectoryAttribute("physicalDeliveryOfficeName")]
public string physicalDeliveryOfficeName
{
get { return _physicalDeliveryOfficeName; }
set
{
if (_physicalDeliveryOfficeName != value)
{
_physicalDeliveryOfficeName = value;
OnPropertyChanged("physicalDeliveryOfficeName");
}
}
}
private string _physicalDeliveryOfficeName;
/// <summary>
/// Contains the description to display for an object. This value is restricted as single-valued for backwards compatibility in some cases but, allowed to be multi-valued in others. See Remarks section for more information.
/// </summary>
[DirectoryAttribute("description")]
public string description
{
get { return _description; }
set
{
if (_description != value)
{
_description = value;
OnPropertyChanged("description");
}
}
}
private string _description;
/// <summary>
/// The display name for an object. This is usually the combination of the users first name, middle initial, and last name.
/// </summary>
[DirectoryAttribute("displayName")]
public string displayName
{
get { return _displayName; }
set
{
if (_displayName != value)
{
_displayName = value;
OnPropertyChanged("displayName");
}
}
}
private string _displayName;
/// <summary>
/// The DistinguishedName property contains the distinguished name of the requested object.
/// </summary>
[DirectoryAttribute("distinguishedName")]
public string distinguishedName
{
get { return _distinguishedName; }
set
{
if (_distinguishedName != value)
{
_distinguishedName = value;
OnPropertyChanged("distinguishedName");
}
}
}
private string _distinguishedName;
[DirectoryAttribute("extensionAttribute1")]
public string extensionAttribute1
{
get { return _extensionAttribute1; }
set
{
if (_extensionAttribute1 != value)
{
_extensionAttribute1 = value;
OnPropertyChanged("extensionAttribute1");
}
}
}
private string _extensionAttribute1;
[DirectoryAttribute("extensionAttribute2")]
public string extensionAttribute2
{
get { return _extensionAttribute2; }
set
{
if (_extensionAttribute2 != value)
{
_extensionAttribute2 = value;
OnPropertyChanged("extensionAttribute2");
}
}
}
private string _extensionAttribute2;
[DirectoryAttribute("extensionAttribute3")]
public string extensionAttribute3
{
get { return _extensionAttribute3; }
set
{
if (_extensionAttribute3 != value)
{
_extensionAttribute3 = value;
OnPropertyChanged("extensionAttribute3");
}
}
}
private string _extensionAttribute3;
// christophe
[DirectoryAttribute("extensionAttribute4")]
public string extensionAttribute4
{
get { return _extensionAttribute4; }
set
{
if (_extensionAttribute4 != value)
{
_extensionAttribute4 = value;
OnPropertyChanged("extensionAttribute4");
}
}
}
private string _extensionAttribute4;
// christophe
[DirectoryAttribute("extensionAttribute5")]
public string extensionAttribute5
{
get { return _extensionAttribute5; }
set
{
if (_extensionAttribute5 != value)
{
_extensionAttribute5 = value;
OnPropertyChanged("extensionAttribute5");
}
}
}
private string _extensionAttribute5;
[DirectoryAttribute("extensionAttribute6")]
public string extensionAttribute6
{
get { return _extensionAttribute6; }
set
{
if (_extensionAttribute6 != value)
{
_extensionAttribute6 = value;
OnPropertyChanged("extensionAttribute6");
}
}
}
private string _extensionAttribute6;
[DirectoryAttribute("extensionAttribute7")]
public string extensionAttribute7
{
get { return _extensionAttribute7; }
set
{
if (_extensionAttribute7 != value)
{
_extensionAttribute7 = value;
OnPropertyChanged("extensionAttribute7");
}
}
}
private string _extensionAttribute7;
[DirectoryAttribute("extensionAttribute8")]
public string extensionAttribute8
{
get { return _extensionAttribute8; }
set
{
if (_extensionAttribute8 != value)
{
_extensionAttribute8 = value;
OnPropertyChanged("extensionAttribute8");
}
}
}
private string _extensionAttribute8;
[DirectoryAttribute("extensionAttribute9")]
public string extensionAttribute9
{
get { return _extensionAttribute9; }
set
{
if (_extensionAttribute9 != value)
{
_extensionAttribute9 = value;
OnPropertyChanged("extensionAttribute9");
}
}
}
private string _extensionAttribute9;
[DirectoryAttribute("extensionAttribute10")]
public string extensionAttribute10
{
get { return _extensionAttribute10; }
set
{
if (_extensionAttribute10 != value)
{
_extensionAttribute10 = value;
OnPropertyChanged("extensionAttribute10");
}
}
}
private string _extensionAttribute10;
[DirectoryAttribute("extensionAttribute11")]
public string extensionAttribute11
{
get { return _extensionAttribute11; }
set
{
if (_extensionAttribute11 != value)
{
_extensionAttribute11 = value;
OnPropertyChanged("extensionAttribute11");
}
}
}
private string _extensionAttribute11;
// fax
[DirectoryAttribute("extensionAttribute12")]
public string extensionAttribute12
{
get { return _extensionAttribute12; }
set
{
if (_extensionAttribute12 != value)
{
_extensionAttribute12 = value;
OnPropertyChanged("extensionAttribute12");
}
}
}
private string _extensionAttribute12;
[DirectoryAttribute("extensionAttribute13")]
public string extensionAttribute13
{
get { return _extensionAttribute13; }
set
{
if (_extensionAttribute13 != value)
{
_extensionAttribute13 = value;
OnPropertyChanged("extensionAttribute13");
}
}
}
private string _extensionAttribute13;
[DirectoryAttribute("extensionAttribute14")]
public string extensionAttribute14
{
get { return _extensionAttribute14; }
set
{
if (_extensionAttribute14 != value)
{
_extensionAttribute14 = value;
OnPropertyChanged("extensionAttribute14");
}
}
}
private string _extensionAttribute14;
[DirectoryAttribute("extensionAttribute15")]
public string extensionAttribute15
{
get { return _extensionAttribute15; }
set
{
if (_extensionAttribute15 != value)
{
_extensionAttribute15 = value;
OnPropertyChanged("extensionAttribute15");
}
}
}
private string _extensionAttribute15;
/// <summary>
/// The ID of an employee.
/// </summary>
[DirectoryAttribute("employeeID")]
public string employeeID
{
get { return _employeeID; }
set
{
if (_employeeID != value)
{
_employeeID = value;
OnPropertyChanged("employeeID");
}
}
}
private string _employeeID;
/// <summary>
/// Contains telephone number of the user's business fax machine.
/// </summary>
[DirectoryAttribute("facsimileTelephoneNumber")]
public string facsimileTelephoneNumber
{
get { return _facsimileTelephoneNumber; }
set
{
if (_facsimileTelephoneNumber != value)
{
_facsimileTelephoneNumber = value;
OnPropertyChanged("facsimileTelephoneNumber");
}
}
}
private string _facsimileTelephoneNumber;
[DirectoryAttribute("altRecipient")]
public string altRecipient
{
get { return _altRecipient; }
set
{
if (_altRecipient != value)
{
_altRecipient = value;
OnPropertyChanged("altRecipient");
}
}
}
private string _altRecipient;
/// <summary>
/// The logon name used to support clients and servers running older versions of the operating system, such as Windows NT 4.0, Windows 95, Windows 98, and LAN Manager. This attribute must be less than 20 characters to support older clients.
/// </summary>
[DirectoryAttribute("sAMAccountName")]
public string sAMAccountName
{
get { return _sAMAccountName; }
set
{
if (_sAMAccountName != value)
{
_sAMAccountName = value;
OnPropertyChanged("sAMAccountName");
}
}
}
private string _sAMAccountName;
[DirectoryAttribute("deliverAndRedirect")]
public bool deliverAndRedirect
{
get { return _deliverAndRedirect; }
set
{
if (_deliverAndRedirect != value)
{
_deliverAndRedirect = value;
OnPropertyChanged("deliverAndRedirect");
}
}
}
private bool _deliverAndRedirect;
/// <summary>
/// Contains the given name (first name) of the user.
/// </summary>
[DirectoryAttribute("givenName")]
public string givenName
{
get { return _givenName; }
set
{
if (_givenName != value)
{
_givenName = value;
OnPropertyChanged("givenName");
}
}
}
private string _givenName;
/// <summary>
/// The home directory for the account. If homeDrive is set and specifies a drive letter, homeDirectory must be a UNC path. Otherwise, homeDirectory is a fully qualified local path including the drive letter (e.g. "c:\directory\folder"). This value can be a null string.
/// </summary>
[DirectoryAttribute("homeDirectory")]
public string homeDirectory
{
get { return _homeDirectory; }
set
{
if (_homeDirectory != value)
{
_homeDirectory = value;
OnPropertyChanged("homeDirectory");
}
}
}
private string _homeDirectory;
/// <summary>
/// Specifies the drive letter to which to map the UNC path specified by homeDirectory. The drive letter must be specified in the form "<DriveLetter>:" where <DriveLetter> is the letter of the drive to map. The <DriveLetter> must be a single, uppercase letter and the colon (:) is required.
/// </summary>
[DirectoryAttribute("homeDrive")]
public string homeDrive
{
get { return _homeDrive; }
set
{
if (_homeDrive != value)
{
_homeDrive = value;
OnPropertyChanged("homeDrive");
}
}
}
private string _homeDrive;
[DirectoryAttribute("ipPhone")]
public string ipPhone
{
get { return _ipPhone; }
set
{
if (_ipPhone != value)
{
_ipPhone = value;
OnPropertyChanged("ipPhone");
}
}
}
private string _ipPhone;
[DirectoryAttribute("mail")]
public string mail
{
get { return _mail; }
set
{
if (_mail != value)
{
_mail = value;
OnPropertyChanged("mail");
}
}
}
private string _mail;
[DirectoryAttribute("mailNickName")]
public string mailNickName
{
get { return _mailNickName; }
set
{
if (_mailNickName != value)
{
_mailNickName = value;
OnPropertyChanged("mailNickName");
}
}
}
private string _mailNickName;
[DirectoryAttribute("memberOf")]
public string[] memberOf
{
get { return _memberOf; }
set
{
if (_memberOf != value)
{
_memberOf = value;
OnPropertyChanged("memberOf");
}
}
}
private string[] _memberOf;
[DirectoryAttribute("mobile")]
public string mobile
{
get { return _mobile; }
set
{
if (_mobile != value)
{
_mobile = value;
OnPropertyChanged("mobile");
}
}
}
private string _mobile;
[DirectoryAttribute("msExchHideFromAddressLists")]
public bool msExchHideFromAddressLists
{
get { return _msExchHideFromAddressLists; }
set
{
if (_msExchHideFromAddressLists != value)
{
_msExchHideFromAddressLists = value;
OnPropertyChanged("msExchHideFromAddressLists");
}
}
}
private bool _msExchHideFromAddressLists;
[DirectoryAttribute("homeMDB")]
public string homeMDB
{
get { return _homeMDB; }
set
{
if (_homeMDB != value)
{
_homeMDB = value;
OnPropertyChanged("homeMDB");
}
}
}
private string _homeMDB;
[DirectoryAttribute("msExchPoliciesExcluded")]
public string msExchPoliciesExcluded
{
get { return _msExchPoliciesExcluded; }
set
{
if (_msExchPoliciesExcluded != value)
{
_msExchPoliciesExcluded = value;
OnPropertyChanged("msExchPoliciesExcluded");
}
}
}
private string _msExchPoliciesExcluded;
[DirectoryAttribute("msExchPoliciesIncluded")]
public string msExchPoliciesIncluded
{
get { return _msExchPoliciesIncluded; }
set
{
if (_msExchPoliciesIncluded != value)
{
_msExchPoliciesIncluded = value;
OnPropertyChanged("msExchPoliciesIncluded");
}
}
}
private string _msExchPoliciesIncluded;
[DirectoryAttribute("msRTCSIP-PrimaryHomeServer")]
public string msRTCSIPPrimaryHomeServer
{
get { return _msRTCSIPPrimaryHomeServer; }
set
{
if (_msRTCSIPPrimaryHomeServer != value)
{
_msRTCSIPPrimaryHomeServer = value;
OnPropertyChanged("msRTCSIPPrimaryHomeServer");
}
}
}
private string _msRTCSIPPrimaryHomeServer;
[DirectoryAttribute("msRTCSIP-UserPolicy")] //DNWithBinary
public object msRTCSIPUserPolicy
{
get { return _msRTCSIPUserPolicy; }
set
{
if (_msRTCSIPUserPolicy != value)
{
_msRTCSIPUserPolicy = value;
OnPropertyChanged("msRTCSIPUserPolicy");
}
}
}
private object _msRTCSIPUserPolicy;
[DirectoryAttribute("msRTCSIP-PrimaryUserAddress ")]
public string msRTCSIPPrimaryUserAddress
{
get { return _msRTCSIPPrimaryUserAddress; }
set
{
if (_msRTCSIPPrimaryUserAddress != value)
{
_msRTCSIPPrimaryUserAddress = value;
OnPropertyChanged("msRTCSIPPrimaryUserAddress");
}
}
}
private string _msRTCSIPPrimaryUserAddress;
[DirectoryAttribute("msRTCSIP-UserEnabled")]
public bool msRTCSIPUserEnabled
{
get { return _msRTCSIPUserEnabled; }
set
{
if (_msRTCSIPUserEnabled != value)
{
_msRTCSIPUserEnabled = value;
OnPropertyChanged("msRTCSIPUserEnabled");
}
}
}
private bool _msRTCSIPUserEnabled;
[DirectoryAttribute("pager")]
public string pager
{
get { return _pager; }
set
{
if (_pager != value)
{
_pager = value;
OnPropertyChanged("pager");
}
}
}
private string _pager;
[DirectoryAttribute("protocolSettings")]
public string[] protocolSettings
{
get { return _protocolSettings; }
set
{
if (_protocolSettings != value)
{
_protocolSettings = value;
OnPropertyChanged("protocolSettings");
}
}
}
private string[] _protocolSettings;
[DirectoryAttribute("scriptPath")]
public string scriptPath
{
get { return _scriptPath; }
set
{
if (_scriptPath != value)
{
_scriptPath = value;
OnPropertyChanged("scriptPath");
}
}
}
private string _scriptPath;
[DirectoryAttribute("sn")]
public string sn
{
get { return _sn; }
set
{
if (_sn != value)
{
_sn = value;
OnPropertyChanged("sn");
}
}
}
private string _sn;
[DirectoryAttribute("targetAddress")]
public string targetAddress
{
get { return _targetAddress; }
set
{
if (_targetAddress != value)
{
_targetAddress = value;
OnPropertyChanged("targetAddress");
}
}
}
private string _targetAddress;
[DirectoryAttribute("telephoneNumber")]
public string telephoneNumber
{
get { return _telephoneNumber; }
set
{
if (_telephoneNumber != value)
{
_telephoneNumber = value;
OnPropertyChanged("telephoneNumber");
}
}
}
private string _telephoneNumber;
[DirectoryAttribute("title")]
public string title
{
get { return _title; }
set
{
if (_title != value)
{
_title = value;
OnPropertyChanged("title");
}
}
}
private string _title;
[DirectoryAttribute("PasswordLastChanged",DirectoryAttributeType.ActiveDs)]
public DateTime PasswordLastChanged { get; set; }
[DirectoryAttribute("PasswordExpirationDate", DirectoryAttributeType.ActiveDs)]
public DateTime PasswordExpirationDate { get; set; }
[DirectoryAttribute("userPrincipalName")]
public string userPrincipalName
{
get { return _userPrincipalName; }
set
{
if (_userPrincipalName != value)
{
_userPrincipalName = value;
OnPropertyChanged("userPrincipalName");
}
}
}
private string _userPrincipalName;
[DirectoryAttribute("proxyAddresses")]
public string[] proxyAddresses
{
get { return _proxyAddresses; }
set
{
if (_proxyAddresses != value)
{
_proxyAddresses = value;
OnPropertyChanged("proxyAddresses");
}
}
}
private string[] _proxyAddresses;
// [DirectoryAttribute("")]
//Filiale, site et localisation a partir du DistinguishedName{get;set;}
[DirectoryAttribute("msExchOmaAdminWirelessEnable")]
public int msExchOmaAdminWirelessEnable
{
get { return _msExchOmaAdminWirelessEnable; }
set
{
if (_msExchOmaAdminWirelessEnable != value)
{
_msExchOmaAdminWirelessEnable = value;
OnPropertyChanged("msExchOmaAdminWirelessEnable");
}
}
}
private int _msExchOmaAdminWirelessEnable;
/// <summary>
/// Flags that control the behavior of the user account.
/// </summary>
[DirectoryAttribute("userAccountControl")]
public int userAccountControl
{
get { return _userAccountControl; }
set
{
if (_userAccountControl != value)
{
_userAccountControl = value;
OnPropertyChanged("userAccountControl");
}
}
}
private int _userAccountControl;
[DirectoryAttribute("AccountExpirationDate", DirectoryAttributeType.ActiveDs)]
public DateTime AccountExpirationDate
{
get { return _AccountExpirationDate; }
set
{
if (_AccountExpirationDate != value)
{
_AccountExpirationDate = value;
OnPropertyChanged("AccountExpirationDate");
}
}
}
private DateTime _AccountExpirationDate;
[DirectoryAttribute("AccountDisabled", DirectoryAttributeType.ActiveDs)]
public bool AccountDisabled { get; set; }
[DirectoryAttribute("employeeType")]
public string employeeType
{
get { return _employeeType; }
set
{
if (_employeeType != value)
{
_employeeType = value;
OnPropertyChanged("employeeType");
}
}
}
private string _employeeType;
public string FirstName
{
get { return givenName; }
set { givenName = value; }
}
public string LastName
{
get { return sn; }
set { sn = value; }
}
public string Profil
{
get { return extensionAttribute2; }
set { extensionAttribute2 = value; }
}
public bool HasAccountExpirationDate
{
get
{
return AccountExpirationDate > new DateTime(1970, 1, 1);
}
}
public bool SetPassword(string password)
{
DirectoryEntry.Invoke("SetOption", new object[] { 7, 1 });
return DirectoryEntry.Invoke("SetPassword", new object[] { password }) == null;
}
public bool CantChangePassword
{
get { return (userAccountControl & (int)UserFlags.PASSWD_CANT_CHANGE) != (int)UserFlags.PASSWD_CANT_CHANGE; }
}
public bool DontExpirePassword
{
get { return (userAccountControl & (int)UserFlags.DONT_EXPIRE_PASSWORD) != (int)UserFlags.DONT_EXPIRE_PASSWORD; }
}
public void Create(string root)
{
DirectoryEntry rootDirectoryEntry = Helper.GetDirectoryEntry(root);
DirectoryEntry = rootDirectoryEntry.Children.Add("cn=" + this.cn, "user");
DirectoryEntry.Properties["SAMAccountName"].Add(this.sAMAccountName);
DirectoryEntry.Properties["sn"].Add(this.sn);
DirectoryEntry.Properties["givenName"].Add(this.givenName);
// On envoie les modifications au serveur
DirectoryEntry.CommitChanges();
DirectoryEntry.Properties["description"].Value = NullIfEmpty(this.description);
DirectoryEntry.Properties["displayName"].Value = NullIfEmpty(this.displayName);
DirectoryEntry.Properties["extensionAttribute2"].Value = NullIfEmpty(this.extensionAttribute2.ToUpper()); // Profil
DirectoryEntry.Properties["employeeType"].Value = NullIfEmpty(this.employeeType);
DirectoryEntry.Properties["employeeID"].Value = NullIfEmpty(this.employeeID);
DirectoryEntry.CommitChanges();
}
public void Delete()
{
DirectoryEntry.DeleteTree();
DirectoryEntry.Close();
}
public void MoveTo(string newParent)
{
var newRoot = Helper.GetDirectoryEntry(newParent);
DirectoryEntry.MoveTo(newRoot);
DirectoryEntry.CommitChanges();
}
private static string NullIfEmpty(string s)
{
return string.IsNullOrEmpty(s) ? null : s;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ActiveDirectory.Model
{
public interface IDirectoryEntity
{
string sAMAccountName { get; set; }
string distinguishedName { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment