Need to Change Linux User Password using powershell

by Dec 3, 2018

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/…/