Jump to content

Recommended Posts

Posted

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,

Posted

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?

Posted (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 by haze1434
Posted

I've never looked at powershell and this syntax rather befuddles me.

Posted (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 by haze1434
Amended script.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...