Hi! I am trying to work on an assignment for school creating new-adusers from a csv. but when i run my foreach loop it only runs the last object. Any help would be appreciated.
PS C:\windows\system32> ForEach ($ADUser in $NewUsers)
{
$First = $ADUsers.First_Name
$Last = $ADUsers.Last_Name
$Name = $First + " " + $Last
$post = $ADUser.PostalCode
$ophone = $ADUser.OfficePhone
$mphone = $ADUser.MobilePhone
New-ADUser -GivenName $Frist -Surname $Last -Name $Name -DisplayName $Name -OfficePhone $ophone -MobilePhone $mphone -PostalCode $post -Path $OU -Verbose
}
VERBOSE: Performing the operation "New" on target "CN=Kimbery Madarang,OU=Finance,DC=ucertify,DC=com".
VERBOSE: Performing the operation "New" on target "CN=Kimbery Madarang,OU=Finance,DC=ucertify,DC=com".
New-ADUser : The specified account already exists
At line:11 char:1
- New-ADUser -GivenName $Frist -Surname $Last -Name $Name -DisplayName ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ResourceExists: (CN=Kimbery Mada...ucertify,DC=com:String) [New-ADUser], ADIdentityAlreadyExistsException
- FullyQualifiedErrorId : ActiveDirectoryServer:1316,Microsoft.ActiveDirectory.Management.Commands.NewADUser
VERBOSE: Performing the operation "New" on target "CN=Kimbery Madarang,OU=Finance,DC=ucertify,DC=com".
New-ADUser : The specified account already exists
At line:11 char:1
- New-ADUser -GivenName $Frist -Surname $Last -Name $Name -DisplayName ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ResourceExists: (CN=Kimbery Mada...ucertify,DC=com:String) [New-ADUser], ADIdentityAlreadyExistsException
- FullyQualifiedErrorId : ActiveDirectoryServer:1316,Microsoft.ActiveDirectory.Management.Commands.NewADUser