0 votes

Hey

I found this code for my Custom Command to autofill Description. Does anyone know how to modify it to handle grandparent i.e. go two levels up?

$parent = $Context.BindToObject($Context.TargetObject.Parent)
$Context.TargetObject.Put("Description", $parent.Get("name"))
$Context.TargetObject.SetInfo()

Best Regards
Debarase

by (100 points)

1 Answer

0 votes
by (272k points)
selected by
Best answer

Hello Debarase,

You can use the following script to update the Description of an object with the name of its grand parent.

# Get grand parent DN
$grnadParentDN = (New-Object "Softerra.Adaxes.Ldap.DN" "%adm-ParentDN%").Parent

if ($grnadParentDN.Leaf.Type -eq "DC")
{
    $Context.LogMessage("Grand parent of object %fullname% is not an OU or container.", "Warning")
    return
}

# Update object description
$Context.TargetObject.Put("Description", $grnadParentDN.Leaf.Value)
$Context.TargetObject.SetInfo()
0

Perfekt, it works beautifully

Related questions

0 votes
2 answers

I've had a couple custom commands configured since 6/2023 and they've been working just fine up until recently (sometime within the past few weeks or so). Here's a general ... something obvious here. But I can't make sense of why this is suddenly an issue.

asked Mar 20 by msinger (110 points)
0 votes
1 answer

Hello, I am looking for a way to add custom text to a custom command. Optimally in HTML format so I can create links. A similar request was made here: https://www. ... info icon. It would be great if you add this possibility in the next version. regards pudong

asked May 6, 2022 by pudong (670 points)
0 votes
1 answer

I have centralized some of my scheduled tasks in Adaxes; a couple not related to AD. One powershell command runs every minute and copies a file between two systems. Is ... to prevent this specific custom command from logging the action as it is quite noisy.

asked Aug 30, 2021 by jbadry (430 points)
0 votes
1 answer

When creating custom commands you have to select the object type. What is the object type for a Business Unit? It doesn't seem to be OU or Container as I can not select ... execute my script against. I've been searching the site and can not find this detail.

asked Jul 5, 2021 by ComputerHabit (790 points)
0 votes
1 answer

I currently have a Custom Command that is configured for User objects, but I would like to perform actions against a Computer object in the same command. E.g. I have a ... Users, there's no Action Set to disable Computers. Is there a workaround here? Thanks!

asked Jul 28, 2020 by bavery (250 points)
3,350 questions
3,051 answers
7,791 comments
545,074 users