i think, i have a better idea. hope you can help me, to solve it with a IF Request.
here the important part of the Script:
Import-Module ActiveDirectory
start-sleep -s 15
$DisabledAccounts = Get-User -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object { $_.UserAccountControl -match 'AccountDisabled' }
$Count = $DisabledAccounts.Count
Add-Content $LogFile "There are $Count disabled accounts that have active mailboxes"
Foreach ($Account in $DisabledAccounts)
{
if ( get-aduser $Account. { $_.LastLogonTimeStamp -lt(get-date).addmonths(-12) } )
{
#$EmailAddress = $Account.PrimarySMTPAddress.tostring()
$Name=$Account.SamAccountName
#Disable-Mailbox $Account.SamAccountName -Confirm:$false
Add-Content $LogFile "$Name, Mailbox has been Disabled"
}
}
Do you have a idea how can i make the IF request ? in the if request i would have oll disabled accounts that are longer offline than 12 months.