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

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
主站蜘蛛池模板: 庆元县| 巴彦淖尔市| 九龙县| 昭苏县| 若羌县| 揭东县| 寿光市| 宿迁市| 霍林郭勒市| 山阴县| 察隅县| 汝城县| 枣强县| 金堂县| 上杭县| 台东市| 天长市| 兴隆县| 肇州县| 萨迦县| 肇州县| 信宜市| 鄂尔多斯市| 北海市| 苗栗市| 镶黄旗| 东平县| 兰州市| 天津市| 建宁县| 光山县| 海口市| 堆龙德庆县| 玉山县| 莒南县| 连江县| 广平县| 壶关县| 大港区| 浦北县| 虎林市|