Changing Account Passwords

I am in a position where I need to script changing some local user account passwords on our machines.
I have a script that can simply change the password of a set user account name e.g. JoeBloggs on a computer using the computername variable.

However, the acocunts that need their passwords changing are dynamically created by the software they are used with. Sophos.

The accounts use the format of:

SophosSAU<first 10 characters of computername> 0

e.g. For "VirusManagement" server, the user acocunt created would be: SophosSAUvirusmanag0

How do I get this variable in to a script so that I can simply run it on each machine (or via GPO) to change the passwords please? Attached is copy of the simple script mentioned above if its of any help to anyone in solving this.

So I am looking for a script to:

- Change the password of local user accounts
- Use the computername variable to locate the user account
- Find the correct user account based on Sopho's user naming convention above

Many, many thanks in advance.
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.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
$computer = $env:computername
$accountname = "SophosSAU"+$computer.Substring(0,10)+"0"


[adsi]$userVariable = “WinNT://$computer/$accountname”
Rainer JeschorCommented:
and this should be the VBScript equivalent (the previous post is Powershell):
Set wshShell = WScript.CreateObject("WScript.Shell")
strComputerName = wshShell.ExpandEnvironmentStrings("%computername%")
strUserName = "SophosSAU" & Left(strComputerName,10) & "0"
Set ObjUser = GetObject("WINNT://"&strComputername&"/" & strUserName)

Open in new window


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
JBrITAuthor Commented:
Many thanks. VBS was preferred.
Can't believe I didnt spot the "Left" component previously!
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
Visual Basic Classic

From novice to tech pro — start learning today.