Replace character in AD description for all computer accounts

Good morning experts!

I am looking for a script (ps prefered) that will replace a character in computer accounts description in a particular OU.

Under MYCompany OU:

If ':' exists, replace it with '.'
and
If '/' exists, replace it with '.'
and
If '(' exists, replace it with ' ' (space)
and
If ')' exists, replace it with ' ' (space)


We have added many descriptions over the years that include these types of characters, but now are running some ps scripts that these characters seem to interfere with.  Periods seem safe, so we'd like to do a mass replace of all of the problem characters to replace them with either periods or spaces.

Your help is appreciated, as always!
IrrylynAsked:
Who is Participating?
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.

becraigCommented:
Something like this should work for you:


Import-Module activedirectory
$servers = Get-ADComputer  -filter * | select -expand DistinguishedName  | % {
$sfull = $_
$sname =  ($_.split(',')[0] -replace "CN=").ToUpper()

if ($sfull -like "*OU=MYCompany*")
{
$newname = $sname -replace ':', '.' -replace '/', '.' -replace '\(', '-' -replace '\)', '-'
write-host "updating $sname to $newname"
}

if ($newname -ne $null)
{
Rename-Computer -ComputerName $sname -NewName $newname -DomainCredential Domain01\Admin01 -Force -Restart -WhatIf
}

}

Open in new window

0
footechCommented:
The following should work.
$DNofOU = "OU=MyCompany,DC=domain,DC=com"
Get-ADComputer -filter * -searchbase $DNofOU -searchscope OneLevel -properties Description | ForEach `
{
    $newDesc = $_.Description -replace "[:/]","." -replace "[()]"," "
    Set-ADComputer $_.samaccountname -description $newDesc
}

Open in new window

0

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
becraigCommented:
Good catch Foo - I really did not read this was for description.

Irrylyn go ahead and ignore my post, I wrote something for a rename of the computer in AD and missed the word "description" too early in the morning without my coffee.
0
IrrylynAuthor Commented:
No worries, craig.  I caught that before I used it (I was lucky enough to have my coffee this morning!)  but it may very well come in handy at another time!

foo:  this worked perfectly, thank you.

You both have such beautiful minds!  Thank you again for your assistance.  EE blows me away every time!
0
IrrylynAuthor Commented:
50 to craig for the work put into that script which I am sure I will need at some point.

450 to Correct answer provided by foo
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.

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.