AD-User remove all group memberships and add new memberships from template user

Can anyone help me out here with a simple and quick Powershell script to accomplish 

Really annoying all those people moving between  Departments.

Parents
No Data
Reply
  • As is often said here and on other forums like this one.

    Well, forums are not really not free script writing service. You need to show us what you 've tried, what failed, what errors you are getting and we'll try and help.

    Yet, what you are asking for is basic stuff:

    1 - You just get the user, then retrieve the groups the user is in, remove the user.

    2 - Get the groups you want the user to be in, get the use and add the user to it.

    So, if you are new to scripting or scripting with PowerShell. Jump over the MS Virtual Academy or YouTube, the search for 'beginning powerShell' and go through all that to get a baseline to avoid confusion and frustration.

    There are built-in cmdlets for this all of the above. See the provided examples from there and combine them for your resolution

        # Get parameters, examples, full and Online help for a cmdlet or function

        # Get a list of all functions
        Get-Command -CommandType Function

        # Get a list of all commandlets
        Get-Command -CommandType Cmdlet

        # Get a list of all functions for the specified name
        Get-Command -Name '*ADGroup*' -CommandType Function

        # Get a list of all commandlets for the specified name
        Get-Command -Name '*ADGroup**'  -CommandType Cmdlet

        # get function / cmdlet details
            (Get-Command -Name Get-ADUser).Parameters
        Get-help -Name Get-ADUser -Examples
        Get-help -Name Get-ADUser -Full
        Get-help -Name Get-ADUser -Online

        (Get-Command -Name Get-ADGroupMember).Parameters
        Get-help -Name Get-ADGroupMember -Examples
        Get-help -Name Get-ADGroupMember -Full
        Get-help -Name Get-ADGroupMember -Online

        (Get-Command -Name Remove-ADGroupMember).Parameters
        Get-help -Name Remove-ADGroupMember -Examples
        Get-help -Name Remove-ADGroupMember -Full
        Get-help -Name Remove-ADGroupMember -Online

        (Get-Command -Name Add-ADGroupMember).Parameters
        Get-help -Name Add-ADGroupMember -Examples
        Get-help -Name Add-ADGroupMember -Full
        Get-help -Name Add-ADGroupMember -Online

        Get-Help about_*
        Get-Help about_Functions

        # Find all cmdlets / functions with a target parameter
        Get-Help * -Parameter Append

        # All Help topics locations
        explorer "$pshome\$($Host.CurrentCulture.Name)"

    ...or use any of the many public articles on the topic. For example:

        PowerShell – Remove Members from AD Groups in bulk

        Imagine that after retrieving the information you now have remove members from AD Groups as a group clean up activity. If you are interested in finding out the empty groups in AD, please head over here.

        'enterprisedaddy.com/2015/04/powershell-remove-members-from-ad-groups-in-bulk'

Children
No Data