你如何添加从CSV文件中的用户使用PowerShell的活动目录(AD)和Exchange?文件、目录、用户、CSV

2023-09-09 21:44:25 作者:回不去┐的过去

将如何使用PowerShell的一个CSV文件中添加一组用户到Active Directory?

How would one add a group of users to Active Directory from a csv file using PowerShell?

CSV文件将包含的第一个,最后一个,电子邮件,临时密码,并描述了用户使用。该OU,权限等可能很难codeD。

The csv file would contain the first, last, email, temp password, and description for the users. The OU, permissions, and etc. could be hard coded.

这个脚本应该还添加Exchange 2007邮箱。

The script should also add an Exchange 2007 email box.

推荐答案

CSV文件应包含一个标题行的所有字段名。

The csv file should contain a header row with all the field names.

下面是code:

$Users = Import-Csv ".\UsersFile.csv"
foreach ($User in $Users)
{
    New-Mailbox -Name $User.Name -Alias $User.MailboxAlias `
        -OrganizationalUnit $User.OU `
        -UserPrincipalName $User.UPN -SamAccountName $User.UserName `
        -FirstName $User.First -Initials $USer.Initial -LastName $User.Last `
        -Password $User.Password -ResetPasswordOnNextLogon $false `
        -Database 'MailboxDatabaseFilename'
}