It's OK, thanks a lot.
Inspired by your scripts, I created two other custom commands to copy other attributes.
The first one :
# Get organization for a user
$sourceOU = $Context.TargetObject.Get("ou")
$sourceDepartment = $Context.TargetObject.Get("department")
$sourceDivision = $Context.TargetObject.Get("division")
$sourceCity = $Context.TargetObject.Get("l")
$sourceBuilding = $Context.TargetObject.Get("cRPLBuildingName")
If ((-Not $sourceOU) -and (-Not $sourceDepartment) -and (-Not $sourceDivision) -and (-Not $sourceCity) -and (-Not $sourceBuilding))
{
$Context.Cancel("L'utilisateur sélectionné n'a pas de Direction, Service ou Pôle, ni de site ou bâtiment.")
}
If ($sourceOU -ne $NULL) {
$ofs = "|"
$Direction = [string]$sourceOU
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText2", $Direction)
}
Else {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText2", "Null")
}
If ($sourceDepartment -ne $NULL) {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText3", $sourceDepartment)
}
Else {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText3", "Null")
}
If ($sourceDivision -ne $NULL) {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText4", $sourceDivision)
}
Else {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText4", "Null")
}
If ($sourceCity -ne $NULL) {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText5", $sourceCity)
}
Else {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText5", "Null")
}
If ($sourceBuilding -ne $NULL) {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText6", $sourceBuilding)
}
Else {
$Context.Initiator.UserAdsObject.Put("adm-CustomAttributeText6", "Null")
}
$Context.Initiator.UserAdsObject.SetInfo()
And the second one :
#Get strings
$sourceOU = $Context.Initiator.UserAdsObject.Get("adm-CustomAttributeText2")
$sourceDepartment = $Context.Initiator.UserAdsObject.Get("adm-CustomAttributeText3")
$sourceDivision = $Context.Initiator.UserAdsObject.Get("adm-CustomAttributeText4")
$sourceCity = $Context.Initiator.UserAdsObject.Get("adm-CustomAttributeText5")
$sourceBuilding = $Context.Initiator.UserAdsObject.Get("adm-CustomAttributeText6")
If ($sourceOU -ne "Null") {
$Direction = $sourceOU.split("|")
$Context.TargetObject.PutEx("ADS_PROPERTY_UPDATE", "ou", $Direction)
}
Else {
$Context.TargetObject.PutEx("ADS_PROPERTY_CLEAR", "ou", $Null)
}
If ($sourceDepartment -ne "Null") {
$Context.TargetObject.Put("department", $sourceDepartment)
}
Else {
$Context.TargetObject.Put("department", $null)
}
If ($sourceDivision -ne "Null") {
$Context.TargetObject.Put("division", $sourceDivision)
}
Else {
$Context.TargetObject.Put("division", $null)
}
If ($sourceCity -ne "Null") {
$Context.TargetObject.Put("l", $sourceCity)
}
Else {
$Context.TargetObject.Put("l", $null)
}
If ($sourceBuilding -ne "Null") {
$Context.TargetObject.Put("cRPLBuildingName", $sourceBuilding)
}
Else {
$Context.TargetObject.Put("cRPLBuildingName", $null)
}
$Context.TargetObject.SetInfo()
It works, but when a source attribute is empty, when I execute the first custom command, I've got an error and I did not find how to mask it.
Could you help me again to do this correctly and nice ? :roll: