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 (273k 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

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

I'd like some help with a script to revoke a users rights to a shared mailbox upon being removed from a security group. I already have the reverse, a script that adds users to a shared mailbox, if they are a member of a group, now I just need the reverse.

asked Mar 20 by dominik.stawny (160 points)
0 votes
1 answer

https://www.adaxes.com/script-repository/remove-all-group-memberships-for-a-user-account-s33.htm I found this script but it only removes 365 groups, security groups, and ... user from all shared mailboxes they are a member of when disabling a user. Thanks!

asked Sep 8, 2023 by silicondt (60 points)
0 votes
1 answer

Hello! how do i manage do get adaxes to remove all groups from the user after one month? We have a Business Rule where you can add an end of Date when the Account ... value field the powershell script works but not with the +1 Month. Thanks for your help!

asked Jun 14, 2023 by eww ag (140 points)
3,374 questions
3,073 answers
7,817 comments
545,371 users