rename local admin account on remote computers using powershell.

Hello,

I need a script to read a text file of computer names and rename the local administrator account to another name.  

I know group policy can do this but I'd like to use powershell.

May someone please advise?

thanks.
nav2567Asked:
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.

nav2567Author Commented:
I am trying this code but it is not working yet.  Someone who knows please advise.  Thanks.

$computers = Get-Content -path C:\computers.txt
$localaccount = Read-Host -prompt "Enter new localaccount name for admin" -assecurestring
$decodedlocalaccount = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($localaccount))
Foreach($computer in $computers)
{
 $computer
 $user = [adsi]"WinNT://$computer/administrator,user"
 $user.SetInfo()
}
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Before any of that you first get the administrator account name (SID ending with -500) because it might be renamed already
0
nav2567Author Commented:
Not yet.  Here is the latest script I use but it is still not working

$computers = Get-Content -path C:\computers.txt
$accountname = Read-Host -prompt "Enter new accountname for administrator" -assecurestring
$decodedaccountname = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($accountname))
Foreach($computer in $computers)
{
 $computer
 $user = [adsi]"WinNT://$computer/administrator,user"
 $user.administrator.rename("newlocaladmin")
 $user.SetInfo()
 }
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Have you tested it locally? Did you all it through the firewall? You also need to add credentials to do it
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
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.