No error, also no result

Hello,

I like to use this script , to create a new account in Ad.

When I walk through the settings , I do get a value for $Username
Only I do not get this user in AD, ( also not when I # silentlycontinue)

Hopefully a pointer in the right direction help me solve to find out what I can do to resolve it.

Thanks for any help,

param(
[string] $OU = 'OU=P01,OU=ADM,OU=Admin',
[string] $DN = (Get-ADDomain).DistinguishedName
)

#$users = import-csv "D:\users\adpiebak1d\documents\PS-script\New-Admin\New accounts.csv"

# This will be the info needed to create the account
$ADM = "adm-fu-"
$FirstName = Read-Host "FirstName is?"
$MiddleInitial = Read-Host "What are the Middle Initals?"
$LastName = Read-Host "Lastname is?"
$Description = Read-Host "Fill in the Ticketnr, and the function"
$Expiration = (get-date).adddays(3)
$FJDomain = "@Fujitsu.com"
$Expiration = (get-date).adddays(360)
$Emailadress = $FirstName + '.' +$LastName +'@'+ $FJDomain

$DefaultPassword= Read-Host "Create a strongpassword"

# setting the values for a adminaccount
$Username = 'adm-fu-' + $lastname.substring(0,4) + $Lastname.substring(0,1)+'1'

$EAPrefBefore = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'

#Check on existinguser, if true write a warning and return to the beginning
If (get-aduser $Username ) {$Username = 'adm-fu-' + $lastname.substring(0,4) + $Lastname.substring(0,1)+'2'
} #end if
Else {"User $username already exists"
}#end else

#Create the New user Account
$NewUserParams = @{
'UserPrincipalName' = $Username
'Name' = $Username
'GivenName' = $FirstName
'Surname' = $LastName
'Description' = $Description
'Emailadress'= $Emailadress
'SamAccountName' = $Username
'AccountPassword' = (ConvertTo-SecureString $DefaultPassword -AsPlainText -Force)
'Enabled' = $
'Initials' = $MiddleInitial
'Path' = "$OU,$Dn"
#'AccountExpirationDate' = Set-ADAccountExpiration $Expiration

#Because of COVID and RDP, do not set " change at next logon"
'ChangePasswordAtLogon' = $false
}

#Create the new user account
New-AdUser @NewUserParams

Set-ADAccountExpiration -Identity $Username -DateTime $Expiration

#Add to the Standard Group if no reference account

#Or compare to existing user

Write-host $Username "is created"

On line 23 you’re setting the error action to “SilentlyContinue” which is why you are not seeing any errors. Comment out this line and hopefully you’ll get an error that will help.

On line 42 you are missing a ‘d’ from ‘Emailaddress’.

When you add the ‘d’ back the script runs successfully.

[quote quote=266687]On line 23 you’re setting the error action to “SilentlyContinue” which is why you are not seeing any errors. Comment out this line and hopefully you’ll get an error that will help.

[/quote]
Thanx fore the reply, unforntunatlety , still no error , also no AdUser.

[quote quote=266699]On line 42 you are missing a ‘d’ from ‘Emailaddress’.

When you add the ‘d’ back the script runs successfully.

[/quote]
Thank you for the correction, I changed it indeed after youre reply.
However, it did not made it happen for a ADUSer.

OK, it ran fine for me after making that change although I note address is spelled incorrectly throughout the script so that requires further correction.

Try commenting out all the parameters with ‘#’ at the beginning of each line (lines 32-42), except for line 33 which is the only mandatory parameter for New-ADUser.

Also, add the -whatif parameter to the New-ADUser command, if it tries to create the user, you should see the ‘What if:’ statement.

Add the parameters back, one-by-one, until you find the culprit.

Also please format your code properly when posting. Here’s the guide if you need a refresher.