I want to write a script that will check all AD Users, who did not connect to their account for more than 30 Days, disable them and move them to an OU, for other i-users, display the message: $user was connected on (Lastlogondate).<\/p>\n
Advertisement
This script will help me to manage dormants Ad Accounts, based on lastlogon date, description for example.<\/p>\n
Thanks in advance for your help<\/p>\n
I know i will have to play with the method $date.adddays(-30), where $date = get-date, but i’m not pretty sure of how i will use it in my script.<\/p>\n
Please help me with your ideas<\/p>","upvoteCount":9,"answerCount":21,"datePublished":"2023-04-10T10:25:21.000Z","author":{"@type":"Person","name":"tkam44","url":"https://community.spiceworks.com/u/tkam44"},"suggestedAnswer":[{"@type":"Answer","text":"
There’s no need to use -Properties * as that will pull a lot of unnecessary data per user. You can use -Properties LastLogonDate. DistinguishedName and SamAccountName will be part of the default property set regardless of what you pass to -Properties.<\/p>\n
I think you want $user.lastlogondate -lt ($date.AddDays(-30)) because older dates are less than newer dates.<\/p>","upvoteCount":0,"datePublished":"2023-04-10T11:05:03.000Z","url":"https://community.spiceworks.com/t/ad-user-management/949772/2","author":{"@type":"Person","name":"adminofthings","url":"https://community.spiceworks.com/u/adminofthings"}},{"@type":"Answer","text":"