Dewey
Dewey

Reputation: 37

Prepend AD User description with PS - Duplicate Update with ForEach

I've seen many code examples where Get-ADUser can be used to append a description with the following code:

get-aduser username -Properties Description | ForEach-Object { Set-ADUser $_ -Description "$($_.Description) Some more stuff" }

I had thought I could simply invert the order of the code in order to prepend, like so:

get-aduser username -properties Description | ForEach-Object { Set-ADUser $_ -Description "Stuff To Use - $($_.Description)"}

The output then becomes:

"Stuff To Use - Stuff To Use"

In essence, whatever is there to start with is wiped out completely and replaced with a doubled up result of the intended goal.

What am I missing here?

Upvotes: 0

Views: 540

Answers (1)

HAL9256
HAL9256

Reputation: 13483

The code is good and it likely ran twice accidentally.

Reset the description, run the code, then refresh Active Directory Users and Computers and recheck.

Upvotes: 1

Related Questions