Я пытаюсь добавить пользователей в группы AD через PowerShell AD. Вот мой текущий код:Добавление пользователей AD в группу безопасности с использованием файла csv с использованием powershell на сервере Windows 2008 r2
Import-Module ActiveDirectory #Import the active directory module
Import-CSV C:\Userlist.csv | ForEach { #Import the csv file and start the for each statement.
$groups [email protected]{
grouparray = $_.group.split(',')
};
$user = @{ #Create the user variable and set the values within
name=$_.name #Call the name field from the csv file
givenname=$_.givenname #Callthe givenname field from the csv file.
surname=$_.surname #call the surname field from the csv file
samaccountname=$_.samaccountname #Call the samaccountname field from the csv file
department=$_.department #call the department field from the csv file.
accountpassword=(ConvertTo-SecureString "[email protected]" -AsPlainText -Force) #set the password
homedirectory=$_.homedirectory #Call the homedirectory field
emailaddress=$_.emailaddress #call the email address field
mobilephone=$_.mobilephone #call the mobile phone field
Path="Ou=People,dc=G3Zone,dc=local" #Path to the OU "People"
Enabled=$True #enable the account
};#@
New-ADUser @user #Create the new user with the information gathered fromthe csv.
add-ADGroupMember -Identity @groups –member $_.samaccountname
} #endforeach
Это мой CSV файл:
name,givenname,surname,samaccountname,department,group,accountpassword,homedirectory,mobilephone,emailaddress
"Todd Fast",Todd,Fast,Tfast,President,ManagerGroup,[email protected],\\Group3\homedirs\Tfast,111-1111,[email protected]
"Joe Doe",Joe,Doe,Jdoe,Accounting VP,"ManagerGroup,AccountingGroup",[email protected],\\Group3\homedirs\Jdoe,111-1112,[email protected]
"Elaine Irving",Elaine,Irving,Eirving,HR VP,"ManagerGroup,HRGroup",[email protected],\\Group3\homedirs\Eirving,111-1113,[email protected]
"Jane Malzur",Jane,Malzur,Jmalzur,Executive Assistant,"ManagerGroup, Corporate",[email protected],\\Group3\homedirs\Jmalzur,111-1114,J[email protected]
Mike Fox,Mike,Fox,Mfox,IS VP,"ManagerGroup,ISGroup",[email protected],\\Group3\homedirs\Mfox,111-1115,[email protected]
Julie Cash,Julie,Cash,Jcash,Accounting,AccountingGroup,[email protected],\\Group3\homedirs\Jcash,111-1116,[email protected]
Manny Greene,Manny,Greene,Mgreene,Accounting,AccountingGroup,[email protected],\\Group3\homedirs\Mgreene,111-1117,[email protected]
Russ Maine,Russ,Maine,Rmaine,HR,HRGroup,[email protected],\\Group3\homedirs\Rmaine,111-1118,[email protected]
Paul Lam,Paul,Lam,Plam,HR,HRGroup,[email protected],\\Group3\homedirs\Plam,111-1119,[email protected]
Tom Scerbo,Tom,Scerbo,Tscerbo,HR,HRGroup,[email protected],\\Group3\homedirs\Tscerbo,111-1120,[email protected]
Kate McCool,Kate,McCool,KMcCool,HR,HRGroup,[email protected],\\Group3\homedirs\KMcCool,111-1121,[email protected]
Lech Walsh,Lech,Walsh,Lwalsh,IS,ISGroup,[email protected],\\Group3\homedirs\Lwalsh,111-1122,[email protected]
Bonnie Clive,Bonnie,Clive,Bclive,IS,ISGroup,[email protected],\\Group3\homedirs\Bclive,111-1123,[email protected]
Esther Male,Esther,Malo,Emalo,IS,ISGroup,[email protected],\\Group3\homedirs\Emalo,111-1124,[email protected]
Ошибки я получаю:
Add-ADGroupMember : Missing an argument for parameter 'Identity'. Specify a par
ameter of type 'Microsoft.ActiveDirectory.Management.ADGroup' and try again.
At C:\test2.ps1:26 char:29
+ add-ADGroupMember -Identity <<<< @groups -member $_.samaccountname
+ CategoryInfo : InvalidArgument: (:) [Add-ADGroupMember], Parame
terBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.ActiveDirectory.Manage
ment.Commands.AddADGroupMember
Кроме того, если это возможно, я хотел бы быть в состоянии создавать и добавлять их в свои собственные домашние каталоги.
Я не знаю, есть ли большая польза для использования массива. Я просто закодировал, и это то, что я должен работать. Если у вас есть более простой способ написания, мне интересно это увидеть. –
ОК. Я только что немного отредактировал свой код, чтобы придумать этот рекламный ролик. Мой сценарий очень большой и делает массу вещей с большим количеством проверок. Поэтому я извлек часть, которую, я думаю, вы можете использовать. Надеюсь, это полезно. –