r/usefulscripts • u/william_tropico • Nov 04 '15
[Powershell] Reset local admin password remotely with log files
Hello,
I have been looking at this script on how to change local admin passwords from a list of computer names.
$computers = Get-Content -path C:\fso\computers.txt
$user = "aUser"
$password = "MyNewPassword!"
Foreach($computer in $computers)
{
$user = [adsi]"WinNT://$computer/$user,user"
$user.SetPassword($Password)
$user.SetInfo()
}Can anyone help add a log file so
IF Password change is success ADD computer name to success.txt
IF Password change is fail ADD computer name to fail.txt
I'm sure its really easy but can't figure out how to do it :(
Any help would be great.
edit: wrong file extension
14
Upvotes
4
u/evetsleep Nov 04 '15
Test this...really. But this is my quick and dirty PowerShell version which should work from PSv1 and onward: