This solution demonstrates how to retrieve the password expiration date of a user account in Active Directory using PowerShell. It uses the Get-ADUser
cmdlet from the Active Directory module and queries the msDS-UserPasswordExpiryTimeComputed
property, which holds the computed expiration date in FILETIME format.
If querying by -Identity
returns an error such as "Cannot find an object with identity," switching to a -Filter
approach with the SamAccountName
is recommended. Also, ensure that the Active Directory module is imported, the domain context is correct, and the executing user has appropriate permissions.
# Import the Active Directory module if not already loaded
Import-Module ActiveDirectory
# Replace 'username' with the actual SamAccountName of the user
$user = Get-ADUser -Filter {SamAccountName -eq "username"} -Properties msDS-UserPasswordExpiryTimeComputed
# Convert the FILETIME to a readable DateTime object
$passwordExpiry = if ($user."msDS-UserPasswordExpiryTimeComputed") {
[datetime]::FromFileTime($user."msDS-UserPasswordExpiryTimeComputed")
} else {
"Password does not expire or no expiration set."
}
# Output the result
[PSCustomObject]@{
UserName = $user.SamAccountName
PasswordExpiry = $passwordExpiry
}
Key Points:
-Filter
with SamAccountName
to avoid identity resolution issues.msDS-UserPasswordExpiryTimeComputed
returns the expiration time as FILETIME.When working with collections in C#, it's common to extract and concatenate specific property values for display or logging purposes. For instance, if you have a list of objects and want to join the values of a particular string property, you can use LINQ in combination with string.Join
.
You have a list of objects, each with a Name
property, and you want to create a single comma-separated string of all names.
Use LINQ to project the property and string.Join
to concatenate the results.
var names = string.Join(", ", items.Select(i => i.Name));
items
is a List<T>
where T
has a Name
property.Select(i => i.Name)
projects the desired property Name
from each Item Item
.string.Join
concatenates the values with a defined separator (e.g., ", "
in this case)..Where(x => !string.IsNullOrEmpty(x.Name))
.This method is clean, efficient, and readable—ideal for transforming object data into user-friendly output or log formats.
DelegatingHandlers can be tested in isolation:
Mock the Inner Handler:
Inject into DelegatingHandler:
Create HttpClient:
This approach allows for unit testing the DelegatingHandler's logic without making actual HTTP calls.
This video tutorial provides a hands-on introduction to jsTree. The walkthrough covers the setup process, basic configuration, and demonstrates how to create a simple tree structure using the library. It’s aimed at developers looking for a quick start with jsTree and practical examples of how it integrates into HTML pages.
Highlights from the video:
checkbox
and search
While the video is specific to jsTree, the concepts are transferable to similar tree view libraries.
Multiple DelegatingHandlers can be chained to create a pipeline:
services.AddTransient<LoggingHandler>(); services.AddTransient<AuthenticationHandler>(); services.AddHttpClient("ChainedClient") .AddHttpMessageHandler<LoggingHandler>() .AddHttpMessageHandler<AuthenticationHandler>();
In this setup, LoggingHandler
processes the request first, followed by AuthenticationHandler
. The order of registration determines the sequence of execution.
After enabling Stereo Mix, configure your playback devices:
This configuration routes audio through both selected devices simultaneously.
C#'s async/await
pattern simplifies asynchronous programming, but integrating it into console applications poses a challenge. The traditional static void Main()
method can't be marked as async
, leading to compiler errors when attempting to use await
directly.
Workaround Strategies:
Separate Async Method: Encapsulate asynchronous operations within a separate method marked as async
. Then, invoke this method from Main()
using .GetAwaiter().GetResult()
to execute it synchronously. This approach ensures exceptions are unwrapped properly, avoiding the AggregateException
that occurs with .Result
or .Wait()
.
Async Main (C# 7.1 and Later): Starting with C# 7.1, you can define the entry point as static async Task Main()
, allowing the use of await
directly within Main()
. This modernizes the approach and simplifies asynchronous code execution in console applications.
For a detailed explanation and code examples see Async/await in a console application.
To create a custom DelegatingHandler:
Inherit from DelegatingHandler:
Register the Handler:
In ASP.NET Core, register the handler using IHttpClientFactory
:
Summary:
This video demonstrates how to generate a TreeView structure using data directly from a SQL Server database in an MVC 4 application. The example uses recursive methods to fetch hierarchical data from a parent-child table (such as a category structure). The TreeView is rendered using a combination of Razor and recursive HTML helpers.
Key Steps:
Best For:
Developers working with older ASP.NET MVC versions who need to generate TreeViews from database-driven content, particularly with dynamic data structures.