# Import the Active Directory module
Import-Module ActiveDirectory
# Get the current date
$currentDate = Get-Date
# Define the number of days of inactivity
$daysInactive = 45
# Calculate the date of last allowed logon
$lastLogonDate = $currentDate.AddDays(-$daysInactive)
# Get all AD users with a value in Custom Attribute 10 and last logon date older than the allowed date
Get-ADUser -Filter {(extensionAttribute10 -like "*") -and (LastLogonDate -lt $lastLogonDate)} -Properties LastLogonDate, extensionAttribute10 | Select-Object SamAccountName, LastLogonDate