0phoi5 Posted May 5, 2016 Posted May 5, 2016 Hi all, I'm using... Get-ADuser $UserID -property MemberOf | % {$_.MemberOf | Get-ADGroup | select Name | sort name} ...to nicely list all the of the Active Directory groups that a user is a member of, in an easy-to-read format. I'm trying to only list the groups that begin with an @ sign. So instead of... @Group 1 @Group 2 Group 3 Group 4 ...I would get just... @Group 1 @Group 2 I'm then looking to remove these groups from the user's account. So, in summary; Get only the MemberOf groups beginning with @, for a user remove user from these groups How would I go about this? I've been playing for a while, but have got no further than the script above. Thank you, Quote
0phoi5 Posted May 5, 2016 Author Posted May 5, 2016 I can list all AD groups beginning with @ by using... Get-ADGroup -Filter {name -like "@*"} -Properties Description | select Name | sort name ... so maybe there's a way to pipe this list to Remove-ADGroupMember? Quote
0phoi5 Posted May 9, 2016 Author Posted May 9, 2016 (edited) Anyone? So far I've got... Get-ADuser [USERID] -property MemberOf | % {$_.MemberOf | Get-ADGroup | select Name | sort name} ... to show all of the groups a user is a member of, and... Get-ADGroup -Filter {name -like "@*"} -Properties Description | select Name | sort name ... to show all groups that exist with @ at the start of them. How do I combine the two? If I use... Get-ADuser [USERID] -property MemberOf | % {$_.MemberOf | Get-ADGroup -Filter {name -like "@*"} -Properties Description | select Name | sort name} ... I get error "The input object cannot be bound to any parameters for the command" Edited May 9, 2016 by haze1434 Quote
cooper Posted May 9, 2016 Posted May 9, 2016 I've never looked at powershell and this syntax rather befuddles me. Quote
0phoi5 Posted May 10, 2016 Author Posted May 10, 2016 (edited) Ah, I think I got it... Get-ADGroup -Filter 'name -like "Foo*"' | Remove-ADGroupMember -identity JoeBloggs ... removes all Active Directory 'Member Of' groups beginning with 'Foo' from user 'JoeBloggs'. Lovely. Edited June 3, 2016 by haze1434 Amended script. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.