- Identity with Windows Server 2016:Microsoft 70-742 MCSA Exam Guide
- Vladimir Stefanovic Sasha Kranjac
- 472字
- 2021-07-02 13:40:48
Performing bulk Active Directory operations
The definition of a bulk operation is a single action that changes multiple objects. Performing a bulk operation is much faster than changing many objects individually. With any type of bulk operation, you need to be more accurate, because any typographic mistake will affect more than one object. The most common bulk operations are as follows:
- Creating new users from a CSV file
- Managing user attributes based on where they belong (OU, Department, Company, and so on)
- Disabling user accounts based on their activity
Although some bulk operations can be done using MMC Snap-ins, PowerShell is the most suitable tool to use. If you want to use PowerShell, you must understand the queries that will be used to list AD DS objects and how to work with .csv files. Then, you can create scripts that perform the bulk operations you need.
Using the Get-ADUser PowerShell cmdlet (for example), you can make a query to AD DS and list all user accounts. However, if you don't add a specific filter to your query, the result is likely to be useless. For this task, you need to understand the filtering parameters:
- SearchBase: Defines the AD DS path to begin searching.
- SearchScope: Defines at what level below the SearchBase the search should be performed.
- ResultSetSize: Defines how many objects to return in response to a query.
- Properties: Defines which object properties to return and display. To return all properties, type *.
All filtering of parameters, especially properties, can be made more precise using the following operators:
- -eq: Equal to
- -ne: Not equal to
- -lt: Less than
- -le: Less than or equal to
- -gt: Greater than
- -ge: Greater than or equal to
- -like: Uses wildcards for pattern matching
Once you make a correct query, you can use pipe ( | ) to perform another command to selected objects. For example, the following PowerShell command will configure the City attribute on all accounts that have the configured Department attribute with a value of IT:
Get-ADUser -Filter {Department -eq "IT"} | Set-ADUser -City London
Another suitable task for performing bulk operations is importing data from a CSV file. CSV files can contain more information than just lists and are often formatted as a spreadsheet. This approach is ideal if you need to create more than one user account at a time and the information populated in the file can be configured as an attribute in the user account. For example, the following is an example of a CSV file and the PowerShell script that will use the attribute from the CSV file:
Name,FirstName,LastName,UPN,SAM,Company
Vladimir Stefanovic,Vladimir, Stefanovic,vladimir.stefanovic@mcsacertguide.local,vladimir.stefanovic,Packt
Sasha Kranjac,Sasha,Kranjac,sasha.kranjac@mcsacertguide.local,sasha.kranjac,Packt
Import-Csv C:\Users.txt | foreach {New-ADUser -Name $_.Name -GivenName $_.FirstName -Surname $_.LastName -UserPrincipalName $_.UPN -SamAccountName $_.SAM –AccountPassword (Read-Host –AsSecureString Enter password) -Enabled $true }
- FTTx PON技術與應用
- EGPRS網(wǎng)絡演進
- 衛(wèi)星通信干擾感知及智能抗干擾技術
- 數(shù)字圖像密碼算法詳解:基于C、C#與MATLAB
- 移動互聯(lián)網(wǎng)技術架構及其發(fā)展(修訂版)
- LED應用技術
- 移動Ad Hoc網(wǎng)絡
- 路由與交換技術
- Android應用開發(fā)從入門到精通
- 5G大規(guī)模天線增強技術
- 智能光網(wǎng)絡運行維護管理
- Premiere Pro CC2018中文版基礎培訓教程
- 電子工程師必備:九大系統(tǒng)電路識圖寶典
- 芯片設計——CMOS模擬集成電路版圖設計與驗證:基于Cadence IC 6.1.7(第2版)
- 36個創(chuàng)意電子小制作——安全衛(wèi)士