PowerShell – Using PoSH SSH Module to shutdown a Synology NAS

October 29, 2018

 

Shutting down a Synology NAS has to be done using an SSH client. And using ROOT access.

SOLUTION :

This is how this is done using the famous PuTTY SSH client

Connect to your NAS

image

Once connected make sure you change to ROOT Access

This is done using this command :

sudo -i

image

Next enter : Poweroff

Of  course you can use Powershell to obtain the same result using the PoSH-SSH module.

See here for more info :

https://audministrator.wordpress.com/2017/10/21/powershell-using-posh-ssh-module-to-access-synology-nas/

Keep in mind that in order to run ‘sudo’ commands you need to use “Invoke-SSHStreamExpectSecureAction” command.

CLS

New-SSHSession -ComputerName NAS_IPAddress -Port ** -Credential (Get-Credential)
$stream = New-SSHShellStream -Index 0
Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command 'sudo -i' -ExpectString 'Password:' -SecureAction (read-host -AsSecureString) -Verbose
$stream.Read()

Enjoy !

Advertisements

PowerShell – Using PoSH SSH Module to access Raspberry Pi3

October 22, 2017

You can use PuTTY to access the RPI3

image

image

Or you can use the PoSH-SSH module to do the same.

So let’s give it a try :

If you connect using this command

New-SSHSession -ComputerName  YourRPI3

Don’t use a domain notification for the user, but just the user name.

image

image

But further then this you can’t get … in this version of PoSH-SSH, so best use the famous PuTTY tool to connect.


PowerShell – Using PoSH SSH Module to access Synology NAS

October 21, 2017

You can now access any SSH device using the PoSH SSH module.

Let’s give it a try using a Synology NAS Device.

Make sure that you enable the SSH Access Service

image

Next make sure you have installed the PoSH-SSH module

Find-Module Posh-SSH

image

Next install it using this command (run as Administrator) :

Find-Module Posh-SSH | Install-Module

After installing you can check the commands available

Get-Command -Module Posh-SSH

image

Now you are ready to make a connection Smile

New-SSHSession -ComputerName YourNASDeviceNAME

image

You can check the session info like this

Get-SSHSession
Get-SSHTrustedHost | fl

image

Let’s run some commands

Invoke-SSHCommand -SessionId 0 -Command "ls -all" | select-Object output -expandproperty output | fl

image

Or using this format :

$result = Invoke-SSHCommand -Index 0 -Command "uname -a; cd /; pwd; ls /volume1" 
$result.Output

image

$result = Invoke-SSHCommand -Index 0 -Command "uname -a" 
$result.Output

image

To stop the session use this command :

Remove-SSHSession -Index 0 -Verbose

image

Enjoy !!