Skip to content

Instantly share code, notes, and snippets.

@weipah
Created April 27, 2012 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weipah/2506769 to your computer and use it in GitHub Desktop.
Save weipah/2506769 to your computer and use it in GitHub Desktop.
Copy ActiveDirectory-Groups from one user to another
function XADGroupCopy() {
param(
[parameter(Mandatory=$true,Position=0,HelpMessage="Von welchem User sollen Berechtigungen kopiert werden?")]
[String]
$fromUser,
[parameter(Mandatory=$true,Position=1,HelpMessage="Welcher User erhaelt die neuen Gruppen?")]
[String]
$toUser
)
$antwort = read-host "Sind Sie sicher? $fromUser --> $toUser (ja/nein)?"
if ($antwort -eq "ja") {
$UserGroups = Get-ADUser –Identity $fromUser -Properties memberOf | Select-Object -ExpandProperty memberOf
# check if Groups are Found
$UserGroups | % {
# Add User to each Group
Add-ADGroupMember -Identity "$($_)" -Members $toUser -ErrorAction SilentlyContinue
}
}
else {
write-host "Abbruch: Es wurden keine Gruppen kopiert!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment