I am trying to understand what this error actually means. Until now, the search for similar requests for help for this error has varied from missing parameters, missing channels, using single or multi-line lines, and also from problems of concatenation, but none of the answers seem to give a definite reason. Therefore, I assume the problem is in the code format (which makes it much harder to track).
This is my script that I am writing to rename active users of the directory for the target unit from any format in which they are currently in to the format firstname.surname.
I created a test unit in AD with some users who will cause errors, and some not. However, users who should not give me an error tell me that "a positional parameter was not found that takes the argument" firstname.surname "
I donβt see what is wrong with the script, but I hope someone will tell me.
Import-Module ActiveDirectory $users = $null $users = Get-ADUser -SearchBase "ou=Testing,ou=Users,dc=my,dc=domain" -Filter * -Properties * foreach ($user in $users) { Write-Host "Processing... $($user)" $newname = $null # Check first/last name is set if (!$user.givenName -or !$user.Surname) { Write-Host "$($user) does not have first name or last name set. Please correct, skipping user." continue } else { $newname = ("$($user.givenName).$($user.Surname)") #Check if new username already exists if (dsquery user -samid $newname) { Write-Host "$($user) requires altered username with initial." if (!$user.Initials) { Write-Host "$($user) does not have any initials set. Please correct, skipping user." continue } $newname = ("$($user.givenName)$($user.Initials).$($user.Surname)") #Check if altered new username already exists if (dsquery user -samid $newname) { Write-Host "$($user) requires manual change. Please correct, skipping user." continue } } try { #Change UPN Set-ADUser $user -userPrincipalName = $newname #Change DN Rename-ADObject -identity $user -Newname $newname } catch { Write-Host "Error when renaming $($user). Error is: $($_.Exception.Message). User requires manual change. Please correct, skipping user." continue } } }
powershell active-directory
David hirst
source share