直接新建邮箱和用户
$Mailbox02 = @{
Name = ‘武思瑜’
Password = (Convertto-Securestring “N#J8xoO&” -Asplaintext -Force)
UserprincipalName = ‘wusiyu@thtfpc.com’
Alias = ‘wusiyu’
DisplayName = ‘武思瑜’
Lastname = ‘武’
FirstName = ‘思瑜’
Database = ‘DB1603’
OrganizationalUnit = ‘OU=国际信息技术(苏州)有限公司,OU=05国际(计算机)公司,OU=北京产业楼,DC=abc,DC=com’
ResetPasswordOnNextLogon = $false
SamAccountName = ‘wusiyu’
}
New-Mailbox $Mailbox02
用户创建后再启用邮箱
查询 新建用户上级所在OU
Get-ADUser -Identity yuanjixin
新建用户后再启用邮箱
$splat = @{
Name = ‘武思瑜’
AccountPassword = (Convertto-Securestring “N#J8xoO&” -Asplaintext -Force)
Enabled = $true
PasswordNeverExpires = $true
SamAccountName = ‘wusiyu’
UserprincipalName = ‘wusiyu@thtfpc.com’
DisplayName = ‘武思瑜’
Office = ‘办公产品中心’
EmailAddress = ‘wusiyu@thtfpc.com’
Title = ‘产品工程师’
Department = ‘移动产品部’
Manager = ‘yuanjixin’
Path = ‘OU=国际信息技术(苏州)有限公司,OU=05国际(计算机)公司,OU=北京产业楼,DC=abc,DC=com’
}
New-ADUser @splat
启用邮箱
$Mailbox01= @{
Identity = ‘wusiyu’
Alias = ‘wusiyu’
DataBase = ‘DB1603’
}
Enable-Mailbox @Mailbox01
查询用户所在的通讯组
Get-ADPrincipalGroupMembership wusiyu | select Name,GroupCategory
Get-ADPrincipalGroupMembership yuanjixin | select Name ,GroupCategory
添加通讯组成员
Add-DistributionGroupMember -Identity ‘同方国际北京全体员工’ -Member wusiyu
批量创建exchange邮箱
定义一个统一密码:password
$MailPasswd =ConvertTo-SecureString password -AsPlainText -Force
2.新建CSV文件NewMail.csv,格式如下
LastName,UserPrincipalName,Database,Alias,DisplayName,OrganizationalUnit,FirstName,Name,
LastName :姓
UserPrincipalName :邮箱地址
Database :指定数据库
Alias :别名
DisplayName :显示名称
OrganizationalUnit :指定一个OU
FirstName :名
Name :姓名
以管理员身份运行:Exchange Management Shell,运行下面命令
Import-Csv D:\test\NewMail.csv | ForEach-Object -Process {New-Mailbox -ResetPasswordOnNextLogon:$False -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -Database $_.Database -Alias $_.Alias -Password $MailPasswd -DisplayName $_.DisplayName -OrganizationalUnit $_.OrganizationalUnit -FirstName $_.FirstName -Name $_.Name}
批量创建邮箱用户
Import-Module activedirectory
Store the data from ADUsers.csv in the $ADUsers variable
SamAccountName Password Name Path Department DisGroup userPrincipalName Title Displayname Description EmailAddress mobilePhone Employeenumber
$Users = Import-Csv -Path C:\BulkAddUser\BulkUsers.csv
foreach ($User in $Users) {
Get-Mailbox -Identity $User.SamAccountName
}
foreach ($User in $Users) {
# Read user data from each field in each row
# the username is used more often, so to prevent typing, save that in a variable
$Username = $User.SamAccountName
# Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username}) {
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else {
# User does not exist then proceed to create the new user account
# create a hashtable for splatting the parameters
$userProps = @{
SamAccountName = $User.SamAccountName
Path = $User.Path
Name = $User.Name
DisplayName = $User.DisplayName
UserPrincipalName = $user.UserPrincipalName
Department = $User.Department
Description = $User.Description
Title = $User.Title
EmailAddress = $User.Email
AccountPassword = (ConvertTo-SecureString $User.Password -AsPlainText -Force)
Enabled = $true
ChangePasswordAtLogon = $true
PasswordNeverExpires = $false
MobilePhone = $User.MPhone
EmployeeNumber = $User.Employeenumber
} #end userprops
New-ADUser @userProps
Enable-Mailbox -Identity $User.SamAccountName -Alias $User.SamAccountName -Database DB1602
Add-DistributionGroupMember -Identity qyjbdrt -Member $User.SamAccountName
Write-Host "The user ADaccount $User is created." -ForegroundColor Green
} #end else
}