0
Completed

PowerShell Transformation: Coalescing Multi-Value DNs

Daniel Walters 5 years ago updated by Matthew Davis (Technical Product Manager) 5 years ago 5

I have two dn.multi fields that I want to coalesce into a single list and also ensure it is unique. It would be something like this

$bothFields = $entity["placepositionoccupants"] + $entity["acpositionoccupants"]

$entity["occupants"] = $bothFields | select-object -unique

This doesn't work though. There's a couple things wrong with it. There's no addition operation for whatever object type the entity is and also when I do a select-object -unique it seems to longer be the type that Broker requires. Any hints on how I can achieve this is powershell? If I had the the object type that's required, I could create a new instance of that and then loop through the two lists adding as appropriate but I don't know the object type and couldn't find it any doco.

Answer

Answer
Completed

Thanks for the feedback Daniel. I've added it to our backlog for action.

This almost works

$entity["Occupants"] = $entity["PlacePositionOccupants"].Value + $entity["ActPositionOccupants"].Value

This creates the list of occupants correctly but the list isn't unique. Whatever I do in PowerShell seems to change the object type and I get the error "The provided value could not be directly cast to the type DistinguishedNameValue and could neither be converted into a MultiValue of that same type. What type of object do I need to create for a multi-value DN?

This worked. I had to use methods that come from the .net object type. I had to guess they were there. This works:

# Append ActPositions onto the PlacePositions multi-value DN list to give the full list of occupants.

foreach ($entity in $entities)

{

$both = $entity["PlacePositionOccupants"].Value

foreach($entry in $entity["ActPositionOccupants"].Value)

{

if ($both.Contains($entry))

{

}

else

{

$both.Add($entry)

}

}

$entity["Occupants"] = $both

}

Under review

Hey Dan,

Great to see you worked it out. As discussed earlier today, if you could provide us with some areas that you feel could be expanded on in the documentation (specifically around the Powershell connector) that would be great.We will use that to expand the documentation in areas people need extra detail.

It'd be great to seem some more documentation around the $entity object in the PowerShell Adapter. What is it's type? Does the type differ for each of the schema types? What methods are available on each type of $entity. Some more examples might help such as casting a dn.multi to a powershell array and back again. Something else that could help would be a method for getting whatever the $entity types are into a PowerShell ISE session so that things can be developed and tested there without needing to run imports and printing things to the $logger.

Answer
Completed

Thanks for the feedback Daniel. I've added it to our backlog for action.