How I can Edit One Word of the Description parameter in AD of 2000 users in a CSV file with powershell??

I have a list of users in a csv file, that I need change only one word of the Description Parameter but I need keep the rest of the sentence equal.

Example:

DESCRIPTION: ERROR (RESPONSIBLE KILE MARCO)

I need replace the word ERROR for the word WORK and result will be DESCRIPTION: WORK (RESPONSIBLE KILE MARCO)

I need a command something like this, but this check all users that the DESCRIPTION is ERROR, and NOT replace only one WORD.

Get-ADUser -LDAPFilter '(Description=ERROR*)' -Properties Description |           
 ForEach-Object {Set-ADObject -Identity $_.DistinguishedName ` -Replace @{Description="WORK $($_.Description)"}}

Open in new window


Help me!
Jose ColmenaresAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Here you go.
Get-ADUser -LDAPFilter '(Description=ERROR*)' -Properties Description | ForEach-Object {
    $description = $_.Description -replace "ERROR","WORK"
    Set-ADObject -Identity $_.DistinguishedName -Description $description
}

Open in new window


It's possible to specify a more specific match.  The above will replace "error" with "work" anywhere in the description string.  So "terror" would become "twork". "errorerrorerrorerror" would become "workworkworkwork".  If that's an issue, you might try something like below.  "\b" indicates a word boundary.
    $description = $_.Description -replace "\bERROR\b","WORK"

Open in new window

There's all sorts of ways to search for a match, but I'd have to see what the false-positives were to be able to come up with a regular expression to avoid them.
0
FOXActive Directory/Exchange EngineerCommented:
Instead of us trying to replace the one word, lets just set the description to what he needs it to be.

1.Set the header of the users listed in the csv file to Users

Import-Csv 'filelocation\yourfile.csv' | %{Set-ADuser $_.Users -Description " WORK (RESPONSIBLE KILE MARCO)"}
0
footechCommented:
Of course, that would only work if he wants the description to be the same for each user.
0
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

Jose ColmenaresAuthor Commented:
Dear, thank you for your answer, the command does not work, does not change the word ERROR for the word WORK.

Also I have a group of 2000 specific users in a csv file and they are the only ones that must be modified, there are many more users in the AD with the word ERROR in the description.
0
footechCommented:
I'm not sure what you're saying doesn't work.  The code has been tested.
This includes the processing of a .CSV for input.
Import-Csv file.csv | ForEach-Object {
    Get-ADUser $_.user -Properties Description | ForEach-Object {
        $description = $_.Description -replace "ERROR","WORK"
        Set-ADObject -Identity $_.DistinguishedName -Description $description
    }
}

Open in new window

If it doesn't work for you then you'll need to provide any received error.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jose ColmenaresAuthor Commented:
The command worked correctly with the users of the list. Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.