Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insufficient access rights to perform the operation -- Powershell

I am writing a simple script to copy AD group membership from one user to the other. I am doing it using the ActiveDirectory module only.

The script looks like it would work and does work up until I try to ad the groups to the user.

Code:

import-module ActiveDirectory
$templateUser = get-ADUser user1
$targetUser = getADUser user2

$groups =get-adprincipalgroupmembership $templateUser
$groups2 = get-ADPrincipalGroupMembership $targetUser

foreach($group in $groups) {
    add-adGroupMember $group $targetUser
}

Error:

Add-ADGroupMember : insufficient access rights to performt the operation
At line:9 char:18
+ FullyQualifiedErrorID : Insufficient access rights to perform the operation,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

Notes/Thoughts:

I am logged in as a normal user, but I ran the powershell as a different user (my admin account). I am not a local admin, but I am an admin on the domain. I am able to add the user to groups if I launch the AD Tools and do it manually (I have permissions to add to those groups).

Edit:

Run the powershell as admin.

like image 798
Jeff Avatar asked Jan 15 '23 13:01

Jeff


1 Answers

Run powershell as administrator.

like image 132
Jeff Avatar answered Jan 31 '23 07:01

Jeff