Last active
August 29, 2015 14:08
-
-
Save KyleOndy/5d4a769a8f8a8082d21b to your computer and use it in GitHub Desktop.
Append-Groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (Get-ADUser -Identity $CopyGroupsFrom -Properties Memberof).MemberOf | Add-ADGroupMember -Members $CopyGroupsTo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .Synopsis | |
| Copies all groups from one user to another | |
| .DESCRIPTION | |
| Queries all the user's groups from Active directory and and appends those groups to another user | |
| .EXAMPLE | |
| Append-Groups -CopyFrom UserA -CopyTo UserB | |
| .NOTES | |
| Must have RAST installed. | |
| #> | |
| function Append-Groups | |
| { | |
| [CmdletBinding(SupportsShouldProcess=$true, | |
| PositionalBinding=$false, | |
| HelpUri = 'http://www.microsoft.com/', | |
| ConfirmImpact='Medium')] | |
| Param | |
| ( | |
| # User that is a member of the groups you wish to copy | |
| [Parameter(Mandatory=$true, | |
| Position=0)] | |
| [ValidateNotNull()] | |
| [ValidateNotNullOrEmpty()] | |
| [string] | |
| $CopyFrom, | |
| # User who needs the groups | |
| [Parameter(Mandatory=$true, | |
| Position=0)] | |
| [ValidateNotNull()] | |
| [ValidateNotNullOrEmpty()] | |
| [string] | |
| $CopyTo | |
| ) | |
| Begin | |
| { | |
| # Are these valid users in AD? | |
| Get-ADUser $CopyFrom -ErrorAction Stop | Out-Null | |
| Get-ADUser $CopyTo -ErrorAction Stop | Out-Null | |
| } | |
| Process | |
| { | |
| (Get-ADUser -Identity $CopyFrom -Properties Memberof).MemberOf | ForEach-Object { | |
| if ($pscmdlet.ShouldProcess("$($_)", "Add $($CopyTo) to group")) | |
| { | |
| Add-ADGroupMember -Members $CopyTo -Identity $_ | |
| } | |
| } | |
| } | |
| End | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment