none
Local admin password change logging

    Question

  • Hello all. I'm very new to PowerShell and attempting to add logging to my local admin password change script which leverages SysInternals pspasswd.exe. Here is what I have so far:

    $computers = get-content "C:\Users\[username]\documents\computers.txt"
    $pspasswd = "C:\Users\[username]\Documents\PSTools\pspasswd.exe"
    
    foreach ($i in $computers)
    
    {
    
    & $pspasswd \\$i administrator Newpasswordthatismoresecure78#
    
    }


    Output looks like this:

    PsPasswd v1.24 - Local and remote password changer
    Copyright (C) 2003-2016 Mark Russinovich
    Sysinternals - www.sysinternals.com

    Password successfully changed.


    PsPasswd v1.24 - Local and remote password changer
    Copyright (C) 2003-2016 Mark Russinovich
    Sysinternals - www.sysinternals.com

    Error changing password:
    Access is denied.

    It works perfectly, I just need a basic txt file log which appends the computer name from the computers.txt list to the script output.

    Any help is greatly appreciated!



    • Edited by mkar38492790 Wednesday, December 5, 2018 7:54 PM
    Wednesday, December 5, 2018 5:16 PM

Answers

  • $computers = get-content C:\Users\[username]\documents\computers.txt
    $pspasswd = 'C:\Users\[username]\Documents\PSTools\pspasswd.exe'
    foreach ($i in $computers) {
        #The computer name will be added to the account name in the log file
        & $pspasswd \\$i administrator Newpasswordhere >> C:\Users\[username]\documents\passwordlog.txt
    }
    


    \_(ツ)_/

    • Marked as answer by mkar38492790 Friday, December 7, 2018 4:00 PM
    Thursday, December 6, 2018 8:58 PM
    Moderator

All replies

  • If you want to log some information you simply have to write the information you want to the destination you want. For example a plain text log file with Out-File or some structured data with Export-CSV. Or you convert whatever you have to XML with ConvertTo-XML or to HTML with ConvertTo-HTML and write it with Out-File. Or you create an event log entry with New-WinEvent.

    Read the help for all this cmdlets and you'll have a good idea how to create a log.

    Regardless of all that: Please format your code as code here in the forum using the code posting tool prvovided. Thanks.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by jrvModerator Wednesday, December 5, 2018 8:21 PM
    Wednesday, December 5, 2018 6:37 PM
  • 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.

    Thursday, December 6, 2018 8:48 AM
    Moderator
  • I am still quite lost. I tried to add a basic log of the output but even this doesn't work:

    $computers = get-content "C:\Users\[username]\documents\computers.txt"
    $pspasswd = "C:\Users\[username]\Documents\PSTools\pspasswd.exe"
    
    $result = foreach ($i in $computers)
    
    {
    
    & $pspasswd \\$i administrator Newpasswordhere
    
    }
    
    Out-File -FilePath "C:\Users\[username]\documents\passwordlog.txt" -InputObject $result

    What I really need is a log with each computer name in the computers.txt list appended to each output.

    Thursday, December 6, 2018 3:49 PM
  • I am still quite lost. I tried to add a basic log of the output but even this doesn't work:

    $computers = get-content "C:\Users\[username]\documents\computers.txt"
    $pspasswd = "C:\Users\[username]\Documents\PSTools\pspasswd.exe"
    
    $result = foreach ($i in $computers)
    
    {
    
    & $pspasswd \\$i administrator Newpasswordhere
    
    }
    
    Out-File -FilePath "C:\Users\[username]\documents\passwordlog.txt" -InputObject $result

    What I really need is a log with each computer name in the computers.txt list appended to each output.

    Hello,

    Maybe you can create a new var to collect a computer name, for example, you can use these two options:

    (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name

    or

    get-childitem -path env:computername

    And use this var in Out-File too:

    Out-File -FilePath "C:\Users\[username]\documents\passwordlog.txt" -InputObject $result




    Felipe Santos

    Microsoft Certified Professional || felipe2ajs@gmail.com || https://www.itvale.eti.br

    Caso o problema tenha sido solucionado, favor marcar como resposta as postagens que resolveram o seu problema

    Thursday, December 6, 2018 4:08 PM
  • $computers = get-content C:\Users\[username]\documents\computers.txt
    $pspasswd = 'C:\Users\[username]\Documents\PSTools\pspasswd.exe'
    foreach ($i in $computers) {
        #The computer name will be added to the account name in the log file
        & $pspasswd \\$i administrator Newpasswordhere >> C:\Users\[username]\documents\passwordlog.txt
    }
    


    \_(ツ)_/

    • Marked as answer by mkar38492790 Friday, December 7, 2018 4:00 PM
    Thursday, December 6, 2018 8:58 PM
    Moderator
  • $computers = get-content C:\Users\[username]\documents\computers.txt
    $pspasswd = 'C:\Users\[username]\Documents\PSTools\pspasswd.exe'
    foreach ($i in $computers) {
        #The computer name will be added to the account name in the log file
        & $pspasswd \\$i administrator Newpasswordhere >> C:\Users\[username]\documents\passwordlog.txt
    }
    


    \_(ツ)_/

    This worked, and not only did it work, it is gloriously simple. THANK YOU!!!
    Friday, December 7, 2018 4:00 PM