Working code
This commit is contained in:
parent
c976387c36
commit
d48a83204c
|
@ -39,13 +39,13 @@ ForEach ($user in $fusers) {
|
|||
|
||||
# Check if user already exists within OU. Skip if so with message stating so. (RAYYAN Contribution)
|
||||
# Source for code (https://morgantechspace.com/2016/11/check-if-ad-user-exists-with-powershell.html)
|
||||
if (Get-ADUser -Filter "SamAccountName -eq '$fname$lname'") {
|
||||
Write-Host "User $fname$lname already exists. Skipping."
|
||||
if (Get-ADUser -Filter {SamAccountName -eq "$($fname + $lname)"}) {
|
||||
Write-Host "User $($fname + $lname) already exists. Skipping."
|
||||
} else {
|
||||
# Construct the full name for user
|
||||
$fullName = "$fname $lname"
|
||||
# Create the user with full name now defined
|
||||
new-ADUser -Name $fullName -SamAccountName ($fname + $lname) -UserPrincipalName "$fname@PSTest.local" -Path $OUpath -AccountPassword $fsecPass -Enabled $true -PassThru
|
||||
new-ADUser -Name "$fname $lname" -SamAccountName ($fname + $lname) -UserPrincipalName "$fname@PSTest.local" -Path $OUpath -AccountPassword $fsecPass -Enabled $true -PassThru
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,5 +54,3 @@ ForEach ($user in $fusers) {
|
|||
# Source for code (https://www.thomasmaurer.ch/2021/01/how-to-add-sleep-wait-pause-in-a-powershell-script/#:~:text=Read%2DHost%20%2DPrompt%20%22Press%20any%20key%20to%20continue...%22)
|
||||
|
||||
Read-Host -Prompt "User creation completed, press any key to close the window."
|
||||
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue