• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

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.
2 Solutions
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

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

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now