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"