0 votes

Hello there,

We have guest accounts created in AD (on our DMZ DC) that use the first initial + last name format for username with the last 4 digits of their mobile number appended to allow for unique and user specific usernames. When running a PowerShell script to update a username after a mobile number is change (to match the format) I'm getting a 'Can't find an object with identity '<currentusername>' error when using the Set-AdmUser cmdlet. The username included in the error is pulled directly from the user being modified via $Context.TargetObject.Get("samAccountName") and when outputting it to the screen via '$Context.LogMessage("Current username: $($currentUsername)", "Information")' it shows the correct current username.

Is there any special way I should be updating a username and UPN from PowerShell?

Thanks,
Chris

by (270 points)
0

Hello Chris,

For troubleshooting purposes, could you post here or send us (support[at]adaxes.com) a screenshot of the Business Rule you are using and the script it executes?

0

The Business rule just executes a PowerShell script when the mobile number is changed, and it does execute when i test. I have some $Context.LogMessage("", "Information") commands in there as validation when the script is run and the output of that is here:

 Succeeded with warnings  
 Details  
 Business Rules: 1 rule encountered while processing your request  
 'Change DMZ Username after info update': Run PowerShell script 'Update username' for the user  
  Current username: ctesting1234  
  Fisrt Name: Chris  
  Last Name: Testing  
  Mobile: 123-123-4567  
  Can't find an object with identity 'ctesting1234'.  
  New username: ctesting4567  
  Can't find an object with identity 'ctesting4567'.  
  New UPN: <ctesting4567@domain.com

Here is my script:

Import-Module Adaxes
#import-module activedirectory

#Get  First Name, last name and mobile
$currentUsername = $Context.TargetObject.Get("samAccountName")
$Context.LogMessage("Current username: $($currentUsername)", "Information")
$fn = $Context.TargetObject.Get("givenName")
$Context.LogMessage("Fisrt Name: $($fn)", "Information")
$ln = $Context.TargetObject.Get("sn")
$Context.LogMessage("Last Name: $($ln)", "Information")
$mobile = $Context.TargetObject.Get("mobile")
$Context.LogMessage("Mobile: $($mobile)", "Information")
$upnSuffix = "domain.com"
$newUsername = ""
$last4ofMobile = ""
$firstInitial = ""

#Remove spaces from Mobile
$mobile = $mobile -replace ' ',''
#Set new mobile number wihtout spaces
$Context.SetModifiedPropertyValue("mobile", $mobile)
#remove everything but digits from mobile
$mobile = $mobile -replace "[^0-9]"

#Get new Username
$firstInitial = $fn.substring(0,1)
if ($mobile.length -gt 4){
    $last4ofMobile = $mobile.Substring($mobile.Length - 4)
}else{
    $Context.LogMessage("Mobile number does not have enough digits, replacing with 1234", "Warning")
    $last4ofMobile = "1234"
}
$newUsername = $firstInitial.ToLower() + $ln.ToLower() + $last4ofMobile
$userLogonName = $newUsername + "@" + $upnSuffix

# Update User Logon Name (pre-Windows 2000)
Set-AdmUser -Identity "$($currentUsername)" -samAccountName "$($newUsername)"
$Context.LogMessage("New username: $($newUsername)", "Information")

# Update User Logon Name
Set-AdmUser -Identity "$($newUsername)" -userPrincipalName "$($userLogonName)"
$Context.LogMessage("New UPN: $($userLogonName)", "Information")
0

Ah it looks like i needed to specify that it should use the adaxes service account, the solution here did the trick for me: Unable to create an OU in a managed domain

Just adding -AdaxesService localhost at the end of the command did it for me

Thanks!
Chris

Please log in or register to answer this question.

Related questions

0 votes
1 answer

Trying to set the primary proxy when doing a name change on an email address.

asked Jul 13, 2023 by mightycabal (1.0k points)
0 votes
0 answers

Hi, I'm currently working with setting up a new Adaxes solution for a customer at my company. The customer needs a solution that can add a security group with full ... help me out here :-) That would be greatly appreciated. Best Regards, Kristoffer Høie.

asked Jun 29, 2016 by krihoie (20 points)
0 votes
1 answer

Hi, I'm trying to add a column to a report to retrieve the last login data from AAD/Graph using the script posted here but i'm running into the ... [0].signInActivity.lastSignInDateTime # Assign a column value to $Context.Value $Context.Value = $lastLogonDate

asked Feb 22, 2022 by richarddewis (260 points)
0 votes
1 answer

I need a list of all the URLs that Adaxes creates in IIS on the server Adaxes is installed on.

asked Feb 6, 2020 by DaralenManta (20 points)
0 votes
1 answer

Occationally Service Desk staff need to clear a DNS record when a desktop has been reimaged but is keeping the same name as loses the ability to manage its original DNS ... running in ADAXES. Can I just install the applet on the ADAXES server using powershell?

asked Jan 17, 2023 by stevehalvorson (110 points)
3,339 questions
3,040 answers
7,758 comments
544,894 users