官术网_书友最值得收藏!

Import export of objects

As an Exchange administrator, you will be asked to create new users, contacts, and export content from Active Directory. This section will show you how to import and export objects to and from Active Directory.

Import user accounts in bulk using a CSV file

If you are an administrator tasked with adding lots of mailboxes for new users who have joined the company, you can use PowerShell to create these users in bulk.

First, you need a CSV file with the list of users that has to be created. The format of the CSV file will look like the following screenshot:

Save this file as UserList.csv.

The first line of the CSV file is important as it will indicate the corresponding values for the fields such as FirstName, Alias, and more for these users. Another thing to notice here is the presence of OU as I wanted to create these users in separate OUs in Active Directory. The password here is the same for simplicity, but it doesn't have to be this way; you can choose to use different passwords for different users.

The next step is to create a few variables to store the data that we will use in the script later. We will use the $Database, $Password, and $Userlist variables. The $Password variable will store the password and will use the CovertTo-SecureString function to convert plain text passwords into a secure string.

You need to check with your Exchange administrator to get the value of the $Database variable as all the mailboxes will be provisioned in this database, or you can choose the automatic mailbox distribution feature in Exchange 2013 that was explained earlier in this chapter. I am using the default database in Exchange 2013; and hence, you will see a random number at the end. You won't see this if you have a naming convention for your databases in your Exchange Organization.

The script will look as this. Save this script as CreateMailboxes.ps1:

$Database = "Mailbox Database 2020596250"
$Userlist = Import-CSV Userlist.csv
ForEach ($User in $Userlist)
{
$Password = ConvertTo-SecureString $User.Password -AsPlainText -Force 
New-mailbox -Password $Password -Database $Database -UserprincipalName $User.UPN -Alias $User.alias -Name $User.Displayname -FirstName $User.Firstname -LastName $User.LastName -OrganizationalUnit $User.OU
}

Import external contacts in bulk using a CSV file

Another frequent request that Exchange and Active Directory administrators get is to import a list of contacts with the external email address from a file. In this section, we will talk about the process. Like we did while importing users, the first step is to create a CSV file with the following columns:

Save this file as ExternalContacts.csv. The next step is to create an Organizational Unit in Active Directory where these contacts will be imported. If you already have one created, skip this step.

The following command will take the input from the previous CSV file and create the contacts in the Contacts OU under Contoso.com:

Import-Csv Externalcontacts.csv | ForEach {New-MailContact -Name $_.DisplayName -Firstname $_.FirstName -LastName $_.LastName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit contoso.com/contacts}

Exporting objects to a CSV file

At times, as an Active Directory or Exchange Administrator, you will be asked to export user objects to a CSV file. Here is a simple way to achieve this with a combination of Get-ADUser, Select-Object, and Export-CSV cmdlets. You can modify the properties that are selected based on your needs:

Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,EmailAddress,LastLogonDate,Manager,Title,Department,CompanywhenCreated,Enabled,MemberOf | Sort-Object -Property Name | export-csv c:\temp\ADUsers.csv
主站蜘蛛池模板: 延津县| 图片| 宝兴县| 密云县| 四子王旗| 兴宁市| 永丰县| 临泽县| 元阳县| 宣化县| 县级市| 本溪市| 东乡族自治县| 霍林郭勒市| 积石山| 沂水县| 铁力市| 延长县| 南陵县| 北碚区| 垫江县| 富裕县| 宿松县| 监利县| 松滋市| 湄潭县| 广灵县| 新源县| 张掖市| 彰化市| 玉山县| 宁河县| 嵩明县| 清流县| 乐山市| 鄂伦春自治旗| 龙门县| 山西省| 南靖县| 奉节县| 邵东县|