problem with batch file. Error logging - need help

Trying to create a script to change passwords on remote PC's.
what i want to do is use the batch files below.
If PC1 is offline the program returns "Error changing password:"
If PC1 is online the program returns "Password successfully changed"
how do I add code to the batch file so that:
A fail will log to a file called failed.txt
A Good change will log to a file call worked.txt
Your help is truly appreciated.

chngpwd.bat
for /f %%c in (wks.txt) do pspasswd.exe \\%%c administrator xxsomepwd

wks.txt
PC1  
PC2
HelpMe01Asked:
Who is Participating?
 
DonNetwork AdministratorCommented:
Sorry mateys, but not only is that article nearly 10 years old...but Microsoft has long ago disabled GP preferences ability to change administrator's password.
http://www.grouppolicy.biz/2014/05/group-policy-preferences-password-behaviour-change-ms14-025/

You should use what is called LAPS.

https://www.microsoft.com/en-us/download/details.aspx?id=46899

The "Local Administrator Password Solution" (LAPS) provides management of local account passwords of domain joined computers. Passwords are stored in Active Directory (AD) and protected by ACL, so only eligible users can read it or request its reset.
0
 
Alex Green3rd Line Server SupportCommented:
Hey mate,

I have a question, I assume you're running this manually right? Why not use powershell and the set-localuser -password?

It's clean

It shows you the errors

It's quicker

It's easier

It will connect to an array of machines easily.

Also, you can use group policy

https://www.agileit.com/news/use-group-policy-to-change-the-password-for-the-local-administrator-account-on-multiple-machines/
0
 
HelpMe01Author Commented:
Great idea for the machines in the domain.
Some of the machines are not in the domain. GP is not going to work for those.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
HelpMe01Author Commented:
I have a tool that works and need to use for my computers that are online and offline. I need help with writing the batch file.
0
 
HelpMe01Author Commented:
Trying to create a script to change passwords on remote PC's.
what i want to do is use the batch files below.
If PC1 is offline the program returns "Error changing password:"
If PC1 is online the program returns "Password successfully changed"
how do I add code to the batch file so that:
A fail will log to a file called failed.txt
A Good change will log to a file call worked.txt
Your help is truly appreciated.

chngpwd.bat
for /f %%c in (wks.txt) do pspasswd.exe \\%%c administrator xxsomepwd

wks.txt
PC1  
PC2
0
 
HelpMe01Author Commented:
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.