Not able to update the Managed_by attribute automatically

Pavan Kumar28
Tera Contributor

Hi All,

i'm trying to update the managedby attribute in AD. For that I have used below script if try to run the script in mid host machine it is working fine.

EX:

$groupname="here i have given group name"

$managedby="here i have given user mailnickname like USER ID in servicenow"

 

# Import the Active Directory module
Import-Module "$executingScriptDirectory\ADSpoke\ActiveDirectoryMain"

 

$groupname = $env:SNC_groupname -replace "%27", "'"
$managedby = $env:SNC_managedby -replace "%27", "'"

 

#SNCLog-ParameterInfo @("Running AddManagedByToADGroup", $groupName, $managedby)

 

# Retrieve the group object
$group = Get-ADGroup -Filter {Name -eq $groupName}

 

if ($group) {
    # Retrieve the manager object
    $manager = Get-ADUser -Identity $managedby

    if ($manager) {
        # Add the ManagedBy attribute to the group
        Set-ADGroup -Identity $group.DistinguishedName -ManagedBy $manager.DistinguishedName
        Write-Output "The group '$groupName' is now managed by '$managedby'."
    } else {
        Write-Output "Manager '$managedby' not found."
    }
} else {
    Write-Output "Group '$groupName' not found."
}

 

 

PavanKumar28_0-1693288539039.png

-->But in AD it's not updating, getting the access related error. Attaching the screenshot for your reference. Can anyone confirm is this error related to access ?. For updating the managed by attribute in AD do we need any access ?

 

PavanKumar28_1-1693288741482.png


Thanks and regards,
Pavan Kumar.

0 REPLIES 0