Hi,<\/p>\n
I need to remove all disabled users from all groups that been disabled more than 30 days. Any ideas?<\/p>","upvoteCount":7,"answerCount":5,"datePublished":"2019-12-31T06:38:22.000Z","author":{"@type":"Person","name":"spiceuser-4lcna","url":"https://community.spiceworks.com/u/spiceuser-4lcna"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi,<\/p>\n
I need to remove all disabled users from all groups that been disabled more than 30 days. Any ideas?<\/p>","upvoteCount":7,"datePublished":"2019-12-31T06:38:22.000Z","url":"https://community.spiceworks.com/t/users-remove-from-all-groups/744741/1","author":{"@type":"Person","name":"spiceuser-4lcna","url":"https://community.spiceworks.com/u/spiceuser-4lcna"}},{"@type":"Answer","text":"
What have you tried? That shouldn’t be too hard to do.<\/p>","upvoteCount":1,"datePublished":"2019-12-31T07:04:21.000Z","url":"https://community.spiceworks.com/t/users-remove-from-all-groups/744741/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
$users=get-aduser -filter 'enabled -eq $false' -Properties samaccountname,memberof |\nSelect-Object samaccountname, @{n=’MemberOf’; e= { ( $_.memberof | ForEach-Object { (Get-ADObject $_).Name }) -join “,” }} \nForeach ($user in $users)\n{ \nSet-ADUser $user.samaccountname -Description \":- $($user.memberof)\"\nGet-ADGroup -Filter {name -notlike \"*domain users*\"} | Remove-ADGroupMember -Members $user.samaccountname -Confirm:$False \n}\n\n<\/code><\/pre>\ni have not received a day that the user has been disabled
\n30 days<\/p>","upvoteCount":1,"datePublished":"2019-12-31T07:17:51.000Z","url":"https://community.spiceworks.com/t/users-remove-from-all-groups/744741/3","author":{"@type":"Person","name":"spiceuser-4lcna","url":"https://community.spiceworks.com/u/spiceuser-4lcna"}},{"@type":"Answer","text":"
Do you mean not logged in or literally disabled.
\nAD does not track changes unless you use some sort of log aggregator to keep track of when an account was disabled. Another possible option is to go off the ‘whenlastchanged’ field, but that gets updated for ANY change in AD, so it wouldn’t be super reliable.<\/p>","upvoteCount":1,"datePublished":"2019-12-31T08:48:13.000Z","url":"https://community.spiceworks.com/t/users-remove-from-all-groups/744741/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Hi, welcome to Spiceworks, and thanks for your query. As a new user here on Spicworks, I urge all new users to read our ‘read before posting;’ post: PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a><\/p>\nYou would need to use a few cmdlets to achieve this:<\/p>\n
First, you would get all groups Get-ADGroups -Filter *.<\/p>\n
For each of those groups, get group membership.<\/p>\n
ANd for each member get the ADUser object (Get-ADUser) to see if they are disabled, and of so removing them from that groups.<\/p>\n
Please have a go at doing this, then post any issues (and the code that is related).<\/p>","upvoteCount":1,"datePublished":"2019-12-31T10:12:43.000Z","url":"https://community.spiceworks.com/t/users-remove-from-all-groups/744741/5","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}}]}}