A Simple example of ForEach-Object

Updated: May 25, 2020

Here is our task: The description attribute for our staging user has the employeeType value that we want. We need to copy the description value over to the employeeType attribute.

Let's start by querying all of our Active Directory users in your staging environment. The below command we are limiting our search to our user OU, and we are grabbing each users properties.

Now just run the below command to set each users employeeType to be description.

To simplify what is going on. Each user is an object, and each object can have multiple properties. For example, the user Abigail Lowe, when we do a "Get-ADUser -Identity alowe -Properties *" PowerShell will output all of Abigail's Active Directory properties. In our ForEach-Object the code is saying for each of the users replace the employeeType, the employeeType equals the description property.

106 views0 comments

Recent Posts

See All