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.4k points)

1 Answer

0 votes
by (288k 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

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)
0 votes
1 answer

I am using this script to remove all users from groups when they are terminated. This script doesn't remove users from Azure only groups just on prem. How would I change ... .LogMessage("Can not remove $U from $GN"+$_.Exception.Message, "Information") } }

asked Jun 18 by mightycabal (1.0k points)
3,541 questions
3,232 answers
8,225 comments
547,802 users