Basically the title. My friend provided me a script to batch change RHEL passwords via Powershell and PuTTY, but the new password I entered doesn't work when I try to log in. I think the issue is that it doesn't escape one of the special characters that's in the new password, but I can't figure out what the new password would have been.

The "new password" I used was similar to this: a1b2c3d"4e5f6g7

I attempted to replace the secure strings for regular strings, or use telnet instead of SSH with a packet capture to determine what exactly is being sent, but none of that has worked thus far.

System.Management.Automation.PSCredential -argumentlist "root",$newrootPassword
     $newrootPassword2 = Read-Host "Retype new root password" -AsSecureString
     $newrootCredential2 = new-object -typename System.Management.Automation.PSCredential -argumentlist "root",$newrootPassword2

    putty.exe -ssh -pw $oldrootCredential.GetNetworkCredential().Password root@$_

    echo y | plink.exe -ssh -v -pw $oldrootCredential.GetNetworkCredential().Password root@$_ "echo root:'$newrootPassword' | chpasswd" 2>&1 

I expected the new password to be a1b2c3d"4e5f6g7; however, this does not work upon login.


1 Answer 1


The problem is you are trying to pass SecureString into something that expects a standard string. The Password property is in SecureString format, you won't be able to pass this to plink, it will just get translated as System.Security.SecureString If the password change actually worked this is what password would have been set.

To translate a SecureString to text format suitable for plink command you need to use function like this example from here

function Get-PlainText()
        [parameter(Mandatory = $true)]
    BEGIN { }
        $bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString);

            return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr);
    END { }

You can test your commands by using Write-Host to output command line value before testing with actual plink.exe. Or you can run ProcMon and filter on Operation is Process Create, then when you see plink.exe launched you can use properties to see the full actual command line that is getting passed.

  • 6
    Dear lord. Who on Earth would... this is so many levels of wrong (not you, the PowerShell). Anyways, you have my upvote just for the courage to get this deep into the abyss.
    – wvxvw
    Jul 15, 2019 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .