locked
Find All the groups a user is member of and replace user from those groups RRS feed

  • Question

  • I am looking for a Powershell command to replace a user from all the groups he is member of with three other users.

    For eg. User1@abc.com needs to be replaced with User2@abc.com, User3@abc.com from all the Groups User1@abc.com is a member of.

    Thanks in advance



    Thursday, May 5, 2016 5:51 AM

Answers

  • PowerShell does not have a command that does that.  You will hav e to write a script.

    Start by using help to learn about how to use these commands.

    Get-AdGroup
    Get-AdGroupMember
    Add-AdGroupMember
    Remove-AdGroupMember.


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Friday, May 6, 2016 7:06 AM
    • Marked as answer by Elaine Jing Thursday, May 12, 2016 8:23 AM
    Thursday, May 5, 2016 6:09 AM
  • I got the answer

    Added the below parameters at the end of my command

    -erroraction continue -Confirm:$false} | Out-File C:\GroupList\Outfile.txt

    • Marked as answer by Elaine Jing Thursday, May 12, 2016 8:23 AM
    Friday, May 6, 2016 6:41 AM

All replies

  • I am looking for a Powershell command to replace a user from all the groups he is member of with three other users.

    For eg. User1@abc.com needs to be replaced with User2@abc.com, User3@abc.com from all the Groups User1@abc.com is a member of.
    Note - that I am trying to do it in Exchange Online Powershell in Office 365
    Thanks in advance




    Thursday, May 5, 2016 5:53 AM
  • PowerShell does not have a command that does that.  You will hav e to write a script.

    Start by using help to learn about how to use these commands.

    Get-AdGroup
    Get-AdGroupMember
    Add-AdGroupMember
    Remove-AdGroupMember.


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Friday, May 6, 2016 7:06 AM
    • Marked as answer by Elaine Jing Thursday, May 12, 2016 8:23 AM
    Thursday, May 5, 2016 6:09 AM
  • Thanks jrv

    I was able to create a list of the groups user is a member of. I found simple command to 

    c:\GroupList\GroupList2.txt" | Remove-DistributionGroupMember -Member User1@abc.com

    Where GroupList2.txt is the list of groups user is member of.

    Are there any parameters I can use in case there are any Errors, to continue running the command but log the Errors for later review?

    Thursday, May 5, 2016 7:46 AM
  • I got the answer

    Added the below parameters at the end of my command

    -erroraction continue -Confirm:$false} | Out-File C:\GroupList\Outfile.txt

    • Marked as answer by Elaine Jing Thursday, May 12, 2016 8:23 AM
    Friday, May 6, 2016 6:41 AM
  • Hi Sam,

    Thanks for the post, glad you got the answer you want  and by the way you can also creat a powershell log with detailed scripts. You can check below article for some reference:

    http://9to5it.com/powershell-logging-function-library/

    Hope it helps.

    Best Regards,

    Elaine


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, May 6, 2016 7:06 AM