Creating AD User, how to show display name automatically without having to enter it?

One mini issue I have with this script. Once I enter the first and last name, it does show the first and last name combined, but then it shows a “colon” after that… which is making us enter a display name. I initially had “Read-Host” in front of $firstname, $lastname… and changed it to “Write-Host” but that didn’t work. Should’nt the display name already be automatically entered once we entered the first and last name?
Here is my script:

#$title = "Create a User Account in Active Directory"

Import-Module ActiveDirectory -EA Stop

# cls removes all text from current display incuding commands and output
# sleep suspends activity in script or session for specified period of time
#  Write-Host allows to use it to emit output to the information stream
sleep 5
cls

Write Host
$firstname = Read-Host "Enter First Name"
Write Host
$lastname = Read-Host " Enter Last Name"
Write Host
$fullname = Write-Host "$firstname $lastname"
Write Host
$i = 1
$logonname = $firstname.substring(0,$i) + $lastname
$OU = "OU=Testing, DC=silvertech, DC=local"
$domain = $env:userdnsdomain
$Description = Read-Host "Enter in the User Description"

DO
{
If ($(Get-ADUser -Filter {SamAccountName -eq $logonname})) {
        Write-Host "WARNING: Logon name" $logonname.toUpper() "already exists!!" -ForegroundColor:Green
        $i++
        $logonname = $firstname.substring(0,$i) + $lastname
        Write-Host
        Write-Host
        Write-Host "Changing Logon name to" $logonname.toUpper() -ForegroundColor:Green
        Write-Host
        $taken = $true
        sleep 10
    } else {
    $taken = $false
    }
} Until ($taken -eq $false)
$logonname = $logonname.toLower()

cls
#Displaying Account information.
Write-Host "======================================="
Write-Host
Write-Host "Firstname:      $firstname"
Write-Host "Lastname:       $lastname"
Write-Host "Display name:   $fullname"
Write-Host "Logon name:     $logonname"
Write-Host "OU:             $OU"
Write-Host "Domain:         $domain"

#Setting minimum password length to 10 characters and adding password complexity.
$PasswordLength = 10
 
Do
{
Write-Host
    $isGood = 0
    $Password = Read-Host "Enter in the Password" -AsSecureString
    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $Complexity = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
 
    if ($Complexity.Length -ge $PasswordLength) {
                Write-Host
            } else {
                Write-Host "Password needs $PasswordLength or more Characters" -ForegroundColor:Green
        }
 
    if ($Complexity -match "[^a-zA-Z0-9]") {
                $isGood++
            } else {
                Write-Host "Password does not contain Special Characters." -ForegroundColor:Green
        }
 
    if ($Complexity -match "[0-9]") {
                $isGood++
            } else {
                Write-Host "Password does not contain Numbers." -ForegroundColor:Green
        }
 
    if ($Complexity -cmatch "[a-z]") {
                $isGood++
            } else {
                Write-Host "Password does not contain Lowercase letters." -ForegroundColor:Green
        }
 
    if ($Complexity -cmatch "[A-Z]") {
                $isGood++
            } else {
                Write-Host "Password does not contain Uppercase letters." -ForegroundColor:Green
        }
 
} Until ($password.Length -ge $PasswordLength -and $isGood -ge 3)

Write-Host
Read-Host "Press Enter to Continue Creating the Account"
Write-Host "Creating Active Directory user account now" -ForegroundColor:Green
 
#Creating user account with the information you inputted.
New-ADUser -Name $fullname -GivenName $firstname -Surname $lastname -DisplayName $fullname -SamAccountName $logonname -UserPrincipalName $logonname@$Domain -AccountPassword $password -Enabled $true -Path $OU -Description $Description -Confirm:$false
 
sleep 2
Add-ADGroupMember -Identity "SilverTech" -Members $logonname
Add-ADGroupMember -Identity "Staff" -Members $logonname
Add-ADGroupMember -Identity "VPN Users" -Members $logonname

Set-ADUser $logonname -emailaddress "$firstname.$lastname@silvertech.com"

 #silvertech
 
Write-Host
 
$ADProperties = Get-ADUser $logonname -Properties *
 
Sleep 3
 
cls
 
Write-Host "========================================================"
Write-Host "The account was created with the following properties:"
Write-Host
Write-Host "Firstname:      $firstname"
Write-Host "Lastname:       $lastname"
Write-Host "Display name:   $fullname"
Write-Host "Logon name:     $logonname"
Write-Host "OU:             $OU"
Write-Host "Domain:         $domain"
Write-Host
#Write-Host$title = "Create a User Account in Active Directory"

2021-10-20 09_34_52-Window
Above, it is giving a blank for display name… I want that to be automatically filled once I enter a first and last name…

Could you please stop posting the entire script every time you have question about 3 or 4 lines of the script?

$firstname = Read-Host -Prompt "Enter First Name"
$lastname = Read-Host -Prompt " Enter Last Name"
$fullname = "$firstname $lastname"
"FullName: '$($fullname)'"

You are lacking the fundamentals. Please take your time to learn the very basics of PowerShell first. It is beyond the scope of a forum to teach you how to write basic PowerShell code.

Ok Im sorry… I’m still a bit new to powershell. But I was still able to write alot of lines of code as you can see. There is nothing wrong in asking here on the forum… :slight_smile:

No, of course not. But you should try to make it easier for us to help you. We’re all here for free in our spare time. :wink: