Hello,
I have been trying to convert an all caps string to title case, and it works, but not as part of a New-ADUser routine.
If I do not include the conversion, the script works fine. Here is part of a ForEach-Object loop…
$params = @{ $preferredname = (Get-Culture).TextInfo.ToTitleCase($_.PreferredName.ToLower()) $lastname = (Get-Culture).TextInfo.ToTitleCase($_.LastName.ToLower()) 'Name' = $preferredname + ' ' + $lastname 'Surname' = $lastname 'DisplayName' = $_.DisplayName 'GivenName' = $preferredname 'EmailAddress' = $_.EmailAddress 'SamAccountName' = $_.UserLogonName 'UserPrincipalName' = ($_.UserLogonName + '@domain') 'Title' = ($_.WorkDuties) 'Department' = ($_.Loc_Name) 'HomeDrive' = "H:" 'HomeDirectory' = ($_.HomeServer + '\HOME\' + $_.UserLogonName) 'Path' = $path 'AccountPassword' = (ConvertTo-SecureString "$($genPass)" -AsPlainText -force) 'ChangePasswordAtLogon' = $true 'Enabled' = $true 'OtherAttributes' = @{'Info'="$($genPass)"} } Try {New-ADUser @params -ErrorAction Continue $successUsers += "$($_.PreferredName) $($_.LastName) - $($_.WorkDuties) at $($_.Loc_Name). $($genPass) `r`n"} Catch {$usersErr += "$($_.Name) - $($_.WorkDuties) at $($_.Loc_Name). `r`n"} } -ErrorAction SilentlyContinue -ErrorVariable +usersErrException
Doing this causes the Try New-ADUser to fail. Removing this and just using ‘Surname’ = $_.LastName, for example, works.