ActiveDirectoryFileManagement 1.0.0
See the version list below for details.
dotnet add package ActiveDirectoryFileManagement --version 1.0.0
NuGet\Install-Package ActiveDirectoryFileManagement -Version 1.0.0
<PackageReference Include="ActiveDirectoryFileManagement" Version="1.0.0" />
paket add ActiveDirectoryFileManagement --version 1.0.0
#r "nuget: ActiveDirectoryFileManagement, 1.0.0"
// Install ActiveDirectoryFileManagement as a Cake Addin #addin nuget:?package=ActiveDirectoryFileManagement&version=1.0.0 // Install ActiveDirectoryFileManagement as a Cake Tool #tool nuget:?package=ActiveDirectoryFileManagement&version=1.0.0
ActiveDirectoryFileManagement
Active Directory Manager
The IActiveDirectoryManager
interface defines a contract for managing users within Active Directory. This includes capabilities to retrieve user details, update user attributes, and fetch specific user entries based on their SAM account name.
Methods
GetUser
Retrieves a DirectoryEntry
object representing a user in Active Directory based on their SAM account name.
DirectoryEntry? GetUser(string samAccountName);
Parameters
samAccountName: The SAM account name of the user to retrieve.Returns
A DirectoryEntry object for the specified user if found; otherwise, null.
Example for GetUser
using ActiveDirectoryFileManagement.Interfaces;
using ActiveDirectoryFileManagement.Services;
using ActiveDirectoryFileManagement.Models;
using System;
// Example setup - ensure you have these using directives
class Program
{
static void Main(string[] args)
{
// Initialize Active Directory settings
var settings = new ActiveDirectorySettings
{
Domain = "yourdomain.com",
Username = "adminusername",
Password = "adminpassword"
};
// Create an instance of your Active Directory manager
IActiveDirectoryManager adManager = new ActiveDirectoryManager(settings);
// SAM account name of the user you want to retrieve
string samAccountName = "jdoe";
// Use the manager to get the user's DirectoryEntry
var userDirectoryEntry = adManager.GetUser(samAccountName);
if (userDirectoryEntry != null)
{
// Successfully retrieved the user, you can now work with the DirectoryEntry object
Console.WriteLine($"User found: {userDirectoryEntry.Properties["name"].Value}");
}
else
{
Console.WriteLine("User not found.");
}
}
}
UpdateUserDetails
Updates specified attributes for a user in Active Directory.
void UpdateUserDetails(string samAccountName, ActiveDirectoryUserDetails userDetails);
- Parameters
samAccountName: The SAM account name of the user whose details are to be updated.
userDetails: An ActiveDirectoryUserDetails object containing the attributes to update.
Example for UpdateUserDetails
class Program
{
static void Main(string[] args)
{
var settings = new ActiveDirectorySettings
{
Domain = "yourdomain.com",
Username = "adminusername",
Password = "adminpassword"
};
IActiveDirectoryManager adManager = new ActiveDirectoryManager(settings);
string samAccountName = "jdoe";
var userDetails = new ActiveDirectoryUserDetails()
.AddDetail("telephoneNumber", "123-456-7890")
.AddDetail("title", "Software Engineer");
adManager.UpdateUserDetails(samAccountName, userDetails);
Console.WriteLine("User details updated successfully.");
}
}
GetUserDetails
Retrieves detailed information about a user from Active Directory.
ActiveDirectoryUserDetails GetUserDetails(string samAccountName);
- Parameters
samAccountName: The SAM account name of the user whose details are to be retrieved. - Returns
An ActiveDirectoryUserDetails object containing the user's details.
Example for GetUserDetails
class Program
{
static void Main(string[] args)
{
var settings = new ActiveDirectorySettings
{
Domain = "yourdomain.com",
Username = "adminusername",
Password = "adminpassword"
};
IActiveDirectoryManager adManager = new ActiveDirectoryManager(settings);
string samAccountName = "jdoe";
var userDetails = adManager.GetUserDetails(samAccountName);
if (userDetails != null && userDetails.UserDetails.Count > 0)
{
Console.WriteLine("User details retrieved successfully:");
foreach (var detail in userDetails.UserDetails)
{
Console.WriteLine($"{detail.Key}: {detail.Value}");
}
}
else
{
Console.WriteLine("User details not found or user has no details.");
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- System.DirectoryServices.AccountManagement (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
ActiveDirectoryFileManagement Package.