Tuesday, January 24, 2017

Execute SSH on PowerShell




PS C:\Users\Administrator\Documents> Find-Module Posh-SSH
 
Version    Name                                Type       Repository           Description                             
-------    ----                                ----       ----------           -----------                             
1.7.7      Posh-SSH                            Module     PSGallery            Provide SSH functionality for executi...
 


PS C:\Users\Administrator\Documents> Install-Module Posh-SSH
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolic
y value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is 'Y'):  

PS C:\Users\Administrator\Documents> New-SSHSession -ComputerName "172.18.3.20" -Credential (Get-Credential)
Windows PowerShell Credential Request : cmdlet Get-Credential at command pipeline position 1
Warning: This credential is being requested by a script or application on the STATBSPAPP remote computer. Enter your cr
edentials only if you trust the remote computer and the application or script requesting it.
 
Supply values for the following parameters:
Credential: 
Enter your user name: root
Enter your password: *****************
Server SSH Fingerprint
Do you want to trust the fingerprint d4:d0:f9:cd:ad:22:ee:da:25:b2:2b:50:45:81:de:5a
[] Y  [] N  [?] Help (default is 'N'): Y
 
SessionId  Host                                                      Connected                                         
---------  ----                                                      ---------                                         
    0      172.18.3.20                                                 True                                            
 
 
PS C:\Users\Administrator\Documents> Invoke-SSHCommand -Index 0 -Command "uname"
 
 
Host       : 172.18.3.20
Output     : {SunOS}
ExitStatus : 0
 
PS C:\Users\Administrator\Documents> Invoke-SSHCommand -Index 0 -Command "su - oracle -c id -u -n"
 
 
Host       : 172.18.3.20
Output     : {uid=901(oracle) gid=900(dba)}
ExitStatus : 0
 


























No comments:

Post a Comment