Recently I had to reset my Root account password on my Synology DS214Play.
I had set the password when I first got the Synology, and of course I forgot it.
Resetting the account is no problem as there is a clear manual available on the Synology forums.
However I wanted to do this trough PowerShell.
One of the reasons I wanted to do this using PowerShell was because I was curious if it was possible to talk to Linux with PS.
First we need to connect to the device using SSH. For this we will need to load a module in PowerShell.
The module is called “Posh-SSH” and is supported from PowerShell 3.0 and up. First lets see if PowerShell can find it.
Now PowerShell found the module, lets install!
Now it has installed the module successfully, let’s see which commands are available.
Seems that “New-SSHSession” is the command we need. Although that specific command isn’t listed there is a “Remove-SSHSession” so it should be available?
Now according to the help, if we want to connect to a remote device we should use the following command:
Ok, now we seem to have a active connection to our Synology trough SSH.
But we also want to run some commands on the device.
According to Posh-SSH we can run single commands using
But after running the command it will close that session. (The connection remains open)
And because we want to reset the Root account we need to be able to use “SUDO”. This is not possible using the command mentioned above because running “SUDO” will ask for credentials. And as the “Invoke-SSHCommand” will close the session after running the command, we can’t enter those.
Luckily they thought about this while building “Posh-SSH”
Specifically for when you want to run multiple command or need the session to stay open for other reasons there is “SSHStream”.
With this the session will stay open so we have more options.
To use the stream option we first have to define which stream we are referring to.
Now that we have defined the stream we can start throwing commands at it.
As we want to reset the Root account password we will need to run “synouser -setpw root Password”
But this command is required to be run under SUDO so it will be “SUDO synouser -setpw root Password”
As mentioned earlier, when running SUDO we need to provide a password. In Linux the reply would be:
The make sure the password request is also filled in we use “Invoke-SSHStreamExpectSecureAction”
The “ –ExpectString” corresponds with the reply the Terminal is giving.
With this command the Root password will be reset to “ Password1”
If we want to know what the terminal is displaying (as it is not a live feed of the terminal) we can run “$stream.Read()”
This way we know what the terminal is replying.
After installing the Posh module the complete script to reset the Root password will be something like:
Don’t use Password1 for your Root password but use something creative
Also we are now using this module to reset a password, but we can also use it to run other command on Linux while using Powershell.