PowerShell remote exec and secure shell

This is not a post about .Net remoting. And its not a post about accessing PowerShell through ssh. Here I'm talking about sending remote executions through rexec, rshell, and secure shell connections.

Rexec and Rshell (rsh.exe) already exist as command line applications, but they do not exists in the PowerShell world (that is, they do not return objects). NetCmdlets send-rexec and send-rshell 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, like so:

PS C:\> send-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:\>

The send-rshell cmdlet gives the exact same output:

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

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


PS C:\> send-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:\> send-ssh -server myserver -user myuser -password mypass -command ls -sshaccept 59:52:C8:DB:C8:3A:...
3A:2C:11:E4                                                                                                             
                                                                                                                        
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:\>


Print | posted on Wednesday, January 24, 2007 1:46 PM

Feedback

# re: PowerShell remote exec and secure shell

Left by chris at 3/11/2007 10:15 AM
Gravatar where do I find these? when I type send-rexec at my ps prompt it's not rec. I have 1.0

# re: PowerShell remote exec and secure shell

Left by chris at 3/11/2007 10:19 AM
Gravatar duh nevermind! I found netcmdlets

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski