cyber8607 Posted August 14, 2014 Posted August 14, 2014 Hi guys, this website helped me alot to make a powerschell script to disconnect mailbox for disabled User. But now i stuck to verify the LastLogonTimeStamp, here my syntax: Get-User -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Where-Object { $_.UserAccountControl -match 'AccountDisabled' -and $_.LastLogonTimeStamp -lt(get-date).addmonths(-12) } But it list all disabled Users witha Mailbox. Not only the Disabled User, that have never Logged in for 12 Months. Can someone help? thank you
Davit2005 Posted August 14, 2014 Posted August 14, 2014 Have you tried to use a filter in the first section to -Filter 'enabled -eq $true' I can't try this myself but something like this Get-User -ResultSize Unlimited -Filter 'enabled -eq $true' -RecipientTypeDetails UserMailbox | Where-Object {$_.LastLogonTimeStamp -lt(get-date).addmonths(-12) }
cyber8607 Posted August 14, 2014 Author Posted August 14, 2014 no, i havent tried it before. i'm not really a big powershell expert i tried to use your command, but it give me the following error: Invoke-Command : Cannot bind parameter 'Filter' to the target. Exception setting "Filter": ""enabled" is not a recognized filterable property.
cyber8607 Posted August 14, 2014 Author Posted August 14, 2014 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now