I am trying to write a script that will add users from a csv file and then add them to a group. I am currently testing with just one user at the is time. The csv file has the following headers
Contents of the Script:
Import-Module ActiveDirectory
$csvfile = Import-Csv -Path C:\PowerShell\Mac_AddUsers.csv
foreach( $user in $csvfile ) {
New-ADUser -Name $user.Username -GivenName $user.GivenName -UserPrincipalName $user.UserPrincipalName -SamAccountName $user.Username -DisplayName $user.DisplayName -Description $user.Description -Path $user.Path -AccountPassword (ConvertTo-SecureString $user.Password -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru }
#Adding the Users to the Groups
foreach ( $user in $csvfile ) {
add-adgroupmember -identity $user.Groupname -Name $user.Username
}
I keep getting the following error when running the script. I am running with domain admins permissions. I have tried with and without quotes for the path in the csv as well.
PS C:\powershell> .\Add_New_User.ps1
New-ADUser : The server is unwilling to process the request
At C:\powershell\Add_New_User.ps1:6 char:1
+ New-ADUser -Name $user.Username -GivenName $user.GivenName -UserPrincipalName $u ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=60c5476d4bee...,DC=example,DC=com:String) [New-ADUser], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Add-ADGroupMember : A parameter cannot be found that matches parameter name 'Name'.
At C:\powershell\Add_New_User.ps1:10 char:45
+ add-adgroupmember -identity $user.Groupname -Name $user.Username
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
Set-ADAccountPassword : A parameter cannot be found that matches parameter name 'PasswordNeverExpires'.
At C:\powershell\Add_New_User.ps1:15 char:128
+ ... inText -force) -PasswordNeverExpires $True -PassThru
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADAccountPassword], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPasswor
d