Quick & Dirty: Copy Active Directory groups from user to user

I have created a small GUI that copies Active Directory groups from one user to another user. The script can be used to quickly transfer all groups of a user to another user account:

Copy Active Directory groups from user to user

The GUI is only very rudimentary, a source user account and a target user account can be selected, a click on "COPY groups from source to target" transfers all groups from the source user to the target user, but leaves existing groups from the target user unchanged.

By clicking on "REPLACE groups from source to target", all groups of the target user are first removed and then all groups of the source user are added.

Copy Active Directory groups from user to user

As already mentioned, this script is quick and dirty, but if you want you can customize it and add error handling and maybe also a security query, because that's all missing...

image

Actually, the AD Picker is the reason for this little script, because I wanted to test it. Although the AD Picker is older, it also works perfectly with Server 2016. I still have a few use cases for the AD Picker in the future.

The AD Object Picker can be downloaded separately here:

Active Directory Object Picker dialog

However, the necessary DLL is already included in the download of the script and does not have to be downloaded separately.

If anyone knows another way to select Active Directory objects within PowerShell scripts, please leave a short comment. Prerequisite for the GUI are the PowerShell CMDLets for Active Directory.

You can download the script here:

The archive also contains the Sapien PowerShell Studio file, the interface can be customized using PowerShell Studio.

10 thoughts on “Quick & Dirty: Active Directory Gruppen von Benutzer zu Benutzer kopieren”

  1. Auch ich kann leider das Script nicht ausführen. Erhalte den Fehler:

    Add-Type : Die Datei oder Assembly „file:///C:\Users\a***\Desktop\GroupCopy\bin\CubicOrange.Windows.Forms.ActiveDirectory.dll“ oder eine Abhängigkeit davon wurde nicht gefunden. Der Vorgang wird nicht unterstützt. (Ausnahme von
    HRESULT: 0x80131515)
    In C:\Users\a****\Desktop\GroupCopy\GroupCopy.Export.ps1:79 Zeichen:2
    + Add-Type -Path (Join-Path -Path (Split-Path $script:MyInvocation. …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

    Reply
  2. Hi Frank,
    jaaa… wenn ich doch mal Ahnung von VB hätte..
    Aber ich habs gerade über die GUI ausprobiert.. das scheitert schon daran, Quell- und Zielbenutzer einzutragen/einzusetzen/auszuwählen.
    Fehlt da vielleicht noch was von ausserhalb des zip-archives?

    Schönen Gruß,
    Andre

    Reply
  3. Hallo,
    dein tool ist genau was ich suche… fast genau!
    Kann man das auch ohne GUI laufen lassen und Quell- und ZielBenutzer als Parameter übergeben?
    Das wäre dann GENAU was ich suche. ;-)

    Andre

    Reply
    • Hi Andre,
      du kannst das Script etwas anpassen, dann ist die Funktion möglich. Eigentlich brauchst du dann nur die paar relevanten Zeilen aus meinem Script kopieren und um einen „param“ Block erweitern.
      Gruß, Frank

      Reply
  4. Leider bekomme ich immer folgende Meldung und der Picker funktioniert dann natürlich nicht:

    Add-Type : Could not load file or assembly ‚file:///[PATH]\GroupCopy\bi
    n\CubicOrange.Windows.Forms.ActiveDirectory.dll‘ or one of its dependencies. Operation is not supported. (Exception
    from HRESULT: 0x80131515)
    At [PATH]\GroupCopy\GroupCopy.Export.ps1:79 char:2
    + Add-Type -Path (Join-Path -Path (Split-Path $script:MyInvocation.MyCommand.Path …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

    Reply

Leave a Comment