Search: 
NetCmdlets - Secure Remoting

Secure Remoting

Accessing PowerShell Through SSH

The PowerShell Server is a secure access remoting enhancement for Microsoft Windows PowerShell.  PowerShell Server gives Systems Administrators and IT professionals the ability access all of the power of Windows PowerShell from any SSH capable terminal or device.

Remote Execution From PowerShell

Rexec and Rshell (rsh.exe) already exist as command line applications, but until now they did not exist in the PowerShell world (that is, they did not return useful, easily scriptable objects). NetCmdlets includes invoke-rexec, invoke-rshell, and invoke-ssh cmdlets take care of this problem. Each remote execution returns a collection of objects that contain the text and whether or not an EOL was present for each line.

Here is an example of using invoke-rexec to issue a directory listing command to a remote rexec host:

PS C:\> invoke-rexec -server server -user user -password pass 
	-command "C:\WINDOWS\system32\cmd exe /c dir c:\"
                                                                            
Text                                                                       EOL
----                                                                       --- 
 Volume in drive C has no label....                                       True 
 Volume Serial Number is 6C32-6256...                                     True 
...                                                                       True 
 Directory of c:\...                                                      True 
...                                                                       True 
12/13/2006  05:41 PM    <DIR>          Documents and Set...               True 
12/17/2006  12:04 PM    <DIR>          Inetpub...                         True 
01/09/2007  03:06 PM    <DIR>          Program Files...                   True 
12/17/2006  12:54 PM    <DIR>          share...                           True 
12/17/2006  12:29 PM    <DIR>          Sun...                             True 
01/21/2007  02:10 PM    <DIR>          TFTP-Root...                       True 
01/09/2007  03:08 PM    <DIR>          Virtual Machines...                True 
01/17/2007  03:02 PM    <DIR>          WINDOWS...                         True 
               7 File(s)        851,124 bytes...                          True 
              13 Dir(s)  15,440,244,736 bytes free...                     True 
              13 Dir(s)  15,440,244,736 bytes free...                     True 
                                                                       
                                                                     
PS C:\>

Similarly, the send-rshell cmdlet gives the exact same output:

PS C:\> invoke-rexec -server server -user user -password pass 
-command "C:\WINDOWS\system32\cmd exe /c dir c:\"

For secure shell connections, NetCmdlets provides the invoke-ssh cmdlet. In the first invoke-ssh example below I just specify my ssh server, user, password, and a command (ls).  It gives similar output:


PS C:\> invoke-ssh -server myserver -user myuser -password mypassword -command ls
                                                         
Do you want to trust the certificate presented?     
The server has presented the key below.        
Fingerprint: 59:52:C8:DB:C8:3A:FE:CF:9D:02:E3:31:3A:2C:11:E4
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y   
                                       
Text                                                                      EOL 
----                                                                      --- 
AssemblyInfo.vb                                                          True 
Documents                                                                True 
EmptyFolder                                                              True 
Lance                                                                    True 
test.exe                                                                 True 
test.ps1                                                                 True 
test.txt                                                                 True 
v6tests                                                                  True 
v8tests                                                                  True 

You'll notice there that the cmdlet stops me to show me the fingerprint presented by the server and make sure I want to accept this host key and continue on. I say yes and the objects are returned. Alternatively I can tell the send-ssh cmdlet the host key fingerprint to accept in the first place, so that it will not require user interaction:

                                                                        
PS C:\> invoke-ssh -server myserver -user myuser -password mypass 
-command ls -sshaccept 59:52:C8:DB:C8:3A:... Text EOL ---- --- AssemblyInfo.vb True Documents True EmptyFolder True Lance True test.exe True test.ps1 True test.txt True v6tests True v8tests True PS C:\>


NetCmdlets

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team.

| About | Privacy Policy | Terms of Use |
© Copyright 2008 /n software inc.