Hi,
I want to know if through an Active Roles Workflow the Firstname attribute and Lastname attribute can be changed so that the first letter of each attribute is UPPERCASE and the rest LOWERCASE.
Any suggestions?
Hi,
I want to know if through an Active Roles Workflow the Firstname attribute and Lastname attribute can be changed so that the first letter of each attribute is UPPERCASE and the rest LOWERCASE.
Any suggestions?
The quick answer to this is yes. It is possible to modify any attribute as part of either a workflow or administration policy.
As we want two different cases in the name string, you're going to want to do this via script.
In a policy script it would look like this:
function onPreCreate($Request) { if($Request.Class -ne "User") {return} ChangeCase $Request } function onPreModify($Request) { if($Request.Class -ne "User") {return} ChangeCase $Request } function IsAttributeModified ([string]$AttributeName, $Request) { $objEntry = $Request.GetPropertyItem($AttributeName, $Constants.ADSTYPE_CASE_IGNORE_STRING) if($objEntry -eq $null) { return $false } if($objEntry.ControlCode -eq 0) { return $false } return $true } function ChangeCase($request) { $Message = "" $Message = "User: $($Request.get("SamAccountName"))" if(IsAttributeModified -AttributeName "Mail" -Request $Request) { $Message = "$($Message)`n`tMail attribute in request" if(-not ($Request.Get("mail") -clike ($Request.Get("mail")).ToLower())) { $Message = "$($Message)`n`tCorrecting Mail" $Message = "$($Message)`n`t`tFrom: $($Request.Get("mail"))" $Message = "$($Message)`n`t`tTo: $($Request.Get("mail").ToLower())" $Request.put("Mail",($Request.Get("mail")).ToLower()) } else { $Message = "$($Message)`n`tNo Mail correction required" } } if(IsAttributeModified -AttributeName "UserPrincipalName" -Request $Request) { if(-not ($Request.Get("UserPrincipalName") -clike ($Request.Get("UserPrincipalName")).ToLower())) { $Message = "$($Message)`n`tCorrecting UPN" $Message = "$($Message)`n`t`tFrom: $($Request.Get("UserPrincipalName"))" $Message = "$($Message)`n`t`tTo: $($Request.Get("UserPrincipalName").ToLower())" $Request.Put("UserPrincipalName",($Request.Get("UserPrincipalName")).ToLower()) } else { $Message = "$($Message)`n`tNo UPN correction required" } } $EventLog.ReportEvent($Constants.EDS_EVENTLOG_WARNING_TYPE,$Message) }
When used in workflows (Create user, or Modify users First and/or last name attbitues), you can use a Modify Request changes activity step, where (as appropriate) the firstname that has been entered, if put through your script, and the result returned back, that would look something like this:
function Change-FirstName($Request) { ChangeCase $Request -AttributeName "givenName" } function Change-LastName($Request) { ChangeCase $Request -AttributeName "sn" } function ChangeCase { param ( $request, $AttributeName=$null ) try { $Value = $Request.Get($AttributeName) } catch { return } $Message = "" $Message = "User: $($Request.get("SamAccountName"))" $Message = "$($Message)`n`tCorrecting attribute $($AttributeName)" $Message = "$($Message)`n`t`tFrom: $($Value)" $Upper = ($Value.ToUpper()).Substring(0,1) $Lower = ($Value.ToLower()).Substring(1,$value.length -1) $value = [string]::Format("{0}{1}",$Upper,$Lower) $Message = "$($Message)`n`t`tTo: $($Value)" $EventLog.ReportEvent($Constants.EDS_EVENTLOG_WARNING_TYPE,$Message) return $value }
There are definitely other methods to change the change, ie the changes on line 33 and 34:
function Change-FirstName($Request) { ChangeCase $Request -AttributeName "givenName" } function Change-LastName($Request) { ChangeCase $Request -AttributeName "sn" } function ChangeCase { param ( $request, $AttributeName=$null ) try { $Value = $Request.Get($AttributeName) } catch { return } $Message = "" $Message = "User: $($Request.get("SamAccountName"))" $Message = "$($Message)`n`tCorrecting attribute $($AttributeName)" $Message = "$($Message)`n`t`tFrom: $($Value)" $textInfo = (Get-Culture).TextInfo $Value = $textInfo.ToTitleCase($Value .ToLower()) $Message = "$($Message)`n`t`tTo: $($Value)" $EventLog.ReportEvent($Constants.EDS_EVENTLOG_WARNING_TYPE,$Message) return $value }
However the larger question here is that should you? Name's are a complex beast, using the conversations above, my result in result people don't want, ie
Entering SmItH, sMITH etc, and you'd get Smith (which is what you want), but case, especially in surnames it complex and generally not as simple as title case.
If the users name is O'Neil, should we be changing to O'neil?
Both McGregor and Mcgregor are valid spellings (I believe), and a person who uses one, might not appreciate the other being used
van Waals might not be Van Waals
Then you also have examples of different countries having different rules for something similar like der Toro vs Der Toro.
Plus a whole host of other rules
I suspect the complexity is why some companies