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?

[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.

Alex GreenProject Systems EngineerCommented:
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
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

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
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

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
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
Windows Batch

From novice to tech pro — start learning today.