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

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 }

主站蜘蛛池模板: 华宁县| 永嘉县| 奉节县| 秦皇岛市| 隆安县| 九龙坡区| 富民县| 阿拉尔市| 外汇| 壶关县| 洛隆县| 祁阳县| 乌什县| 拉萨市| 新郑市| 荃湾区| 元谋县| 于都县| 大理市| 广安市| 台安县| 田东县| 肇州县| 宁明县| 仁寿县| 平武县| 横山县| 义马市| 噶尔县| 西吉县| 涞源县| 固安县| 潞城市| 定远县| 衡阳县| 万源市| 成武县| 来宾市| 云霄县| 诏安县| 房山区|