0 votes

Trying to remove the Aprostrophe from a name in several different area's, "samAccountName", "userPrincipalName", "mail" using this script run before user creation, but it's not working.

Example, change the name O'Connel, to OConnel.

I run a similar script but it removes spaces and works well.

$properties = @("samAccountName", "userPrincipalName", "mail") # TODO: modify me

foreach ($property in $properties)
{
    if ($Context.IsPropertyModified($property))
    {
        $value = $Context.GetModifiedPropertyValue($property)
        if ($value.Contains(" "))
        {
            # Remove apostrophe
            $value = $value.Replace("'", "")

            # Update property
            $Context.SetModifiedPropertyValue($property, $value)

            # Log message
            $Context.LogMessage("Spaces have been removed from $property", "Information")
        }
    }
}
by (1.5k points)

1 Answer

0 votes
by (294k points)

Hello,

The thing is that in the if statement your script checks whether a property value contains spaces and only then removes apostrophes. If the value does not contain spaces, it will not be updated. For the script to work, please, replace this line in your script

if ($value.Contains(" "))

with the following one:

if ($value.Contains("'"))

0

Thanks, totally missed that!

Related questions

0 votes
1 answer

My HR deparment has the ability to export users with managers report to Excel, however the user's picture in embeded into the name column and there is no way to remove it from the report nor from the Excel exported file. Please help.

asked Aug 29 by jurbina (40 points)
0 votes
1 answer

Adaxes version is 2018.2. I have build a custom report, and I don't want the 'Name' column with the pictures to appear in it. But it seem to be mandatory, it is greyed ... . Is there a way to remove / hide / or change the mandatory attribute or column ? Thanks

asked Jan 9, 2020 by Isabelle (50 points)
0 votes
1 answer

Hi, Some rules were accidentally created with the InetOrgPerson (it is selected by default). Is it any way to remove it from the rule and leave only User as Object Type for the rule? Thanks

asked Apr 24 by AnatolieP (50 points)
0 votes
1 answer

Just wanted to know if we could: Change the name of "Rename" Hide it altogether from the user page We've created a custom rename comand would prefer to simplify the user interface.

asked Nov 22 by msheppard (610 points)
0 votes
1 answer

Hi, would it be possible to script a workstation in AD and also directly from our local SCCM environment ?

asked Oct 28 by ddesmedt (40 points)
3,588 questions
3,277 answers
8,303 comments
548,086 users