PowerShell – Using PoSH SSH Module to access Synology NAS

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 !!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: