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?
 
footechConnect With a Mentor Commented:
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
 
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
footechCommented:
Of course, that would only work if he wants the description to be the same for each user.
0
 
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
 
Jose ColmenaresAuthor Commented:
The command worked correctly with the users of the list. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.