Asked by:
Powershell logging

Question
-
I'm in the process of changing our domain local administrator account on about 500 machines and would like to log either the success or failure of each machine. In short, I'm having a great deal of difficulty...
$computers = Get-Content -Path "C:\Temp\Password.txt" $useracct = "Administrator" $password = "MyNewPassword" foreach ($computer in $computers) { Write-Host "Setting $useracct's password on $computer" $user = [adsi]"WinNT://$computer/$useracct,user" $user.SetPassword($password) $user.SetInfo() Write-Host "Password set on $computer" }
HELP!!!
DHeinz
Friday, December 7, 2018 10:10 PM
All replies
-
I don't see where you are logging anything. You need to output something and probably output to a file.
\_(ツ)_/
Friday, December 7, 2018 10:40 PM -
all you have to do is to use Export command:
$computers = Get-Content -Path "C:\Temp\Password.txt" $useracct = "Administrator" $password = "MyNewPassword" foreach ($computer in $computers) { Write-Host "Setting $useracct's password on $computer" $user = [adsi]"WinNT://$computer/$useracct,user" $user.SetPassword($password) $user.SetInfo() Write-Host "Password set on $computer"
Export-Csv -Path C:\userspasswords.csv -Append -InputObject $user }
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Monday, December 10, 2018 3:26 AM
- Unproposed as answer by jrv Wednesday, May 1, 2019 9:28 AM
Saturday, December 8, 2018 6:01 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Tuesday, December 11, 2018 6:17 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Monday, December 24, 2018 5:46 AM -
Hi
Did we able to solve your problem? if you have more questions about this process, feel free to ask them
Wednesday, May 1, 2019 9:12 AM -
A bit of criticism. The post is very old and was obviously abandoned. The answer proposed clearly fail to answer the question asked.
The user asks to log "successes" and "failures". The proposals will only output the string conversion of an ADSI computer object. I do not think these counts as an answer.
Any error will cause an indeterminate number of exceptions with no logging.
"SetPassword" never requires the use of "SetInfo". It is a complete method. Only property assignments require "SetInfo".
\_(ツ)_/
Wednesday, May 1, 2019 9:28 AM