Need to Change Linux User Password using powershell

Hi All


I refereed the below post and came up with the below code for changing the password for a user


$Command = "sudo passwd TestUser"

$Command1 = (Invoke-SSHStreamExpectAction -ShellStream $stream -Command $Command -ExpectString "(current) UNIX password:" -Action "test" -TimeOut 10)

sleep -s 2

$stream.Read()


$Command2= (Invoke-SSHStreamExpectAction -ShellStream $stream -Command $Command -ExpectString "New password:" -Action "Password1" -TimeOut 10)

$stream.Read()

sleep -s 2

$Command3= (Invoke-SSHStreamExpectAction -ShellStream $stream -Command $Command -ExpectString "Retype new password:" -Action "Password1" -TimeOut 10)

sleep -s 2

$stream.Read()


The Password is changing..but the problem is it is not changing as per mentioned in the -Action. when i am going back and try to login using both old and new password i am not able to.

Can anyone help me here.

www.reddit.com/.../

Parents
No Data
Reply
  • Personally, I've not had a reason to use this cmdlet/module, since Windows 10 allows the use of bash natively via WSL/Ubuntu or other Linux versions from teh Windows App Store, so why not just use that.

    Install Windows Subsystem for Linux (WSL) on Windows 10
    https://docs.microsoft.com/en-us/windows/wsl/install-win10

    Example of bash commands fro password changes:
    https://www.systutorials.com/39549/changing-linux-users-password-in-one-command-line

    As for ...

    "
    The Password is changing..
    but the problem is it is not changing as per mentioned in the -Action.
    when i am going back and try to login using both old and new password i am not able to.
    "

    So, some reset action is happening since you cannot use the old password any longer.
    As for not being able to use the new passwords, says, the password was never set to what you sent, but something else or blanked out because of some potential errant action/activity or unreported failure.

Children