Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. PS C:WINDOWSsystem32> Function Invoke-SSH
  2. {
  3. Param($Hostname,$Username,$Password,$CommandArray,$PlinkAndPath,
  4. $ConnectOnceToAcceptHostKey = $true)
  5.  
  6. $Target = $Username + '@' + $Hostname
  7. $plinkoptions = "-ssh $Target -pw $Password"
  8.  
  9.  
  10. $CommandArray | % {$remoteCommand += $Commands}
  11.  
  12. #plist prompts to accept client host key. This section will
  13. login and accept the host key then logout.
  14. if($ConnectOnceToAcceptHostKey)
  15. {
  16. $PlinkCommand = [string]::Format('echo y | & "{0}" {1}
  17. exit',$PlinkAndPath, $plinkoptions )
  18. #Write-Host $PlinkCommand
  19. $msg = Invoke-Expression $PlinkCommand
  20. }
  21.  
  22. #format plist command
  23. $PlinkCommand = [string]::Format('& "{0}" {1} "{2}"',
  24. $PlinkAndPath,$plinkoptions , $remoteCommand)
  25.  
  26. #ready to run the following command
  27. #Write-Host $PlinkCommand
  28. $msg = Invoke-Expression $PlinkCommand
  29. $msg | Out-File -FilePath
  30. C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTest
  31. DeLoAutoLog.txt -Append
  32.  
  33. }
  34.  
  35. #Plink path, credentials and target server definition
  36. $PlinkAndPath
  37. = "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTestplink.exe"
  38. $Username = "cisco"
  39. $Password = "cisco"
  40. $Hostname = "20.1.1.2"
  41. #Commands to execute on the remote ssh host.
  42. $Commands += "show version"
  43.  
  44. Output:
  45.  
  46. Invoke-SSH -User $Username -Hostname $Hostname -Password $Password
  47. -PlinkAndPath $PlinkAndPath -CommandArray $Commands
  48. plink.exe : FATAL ERROR: SSH protocol version 2 required by configuration
  49. but not provided by server
  50. At line:1 char:10
  51. + echo y | & "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTes ...
  52. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. + CategoryInfo : NotSpecified: (FATAL ERROR: SS...vided by
  54. server:String) [], RemoteException
  55. + FullyQualifiedErrorId : NativeCommandError
  56.  
  57. plink.exe : FATAL ERROR: SSH protocol version 2 required by configuration
  58. but not provided by server
  59. At line:1 char:1
  60. + & "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTestplink.e ...
  61. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. + CategoryInfo : NotSpecified: (FATAL ERROR: SS...vided by
  63. server:String) [], RemoteException
  64. + FullyQualifiedErrorId : NativeCommandError
  65.  
  66.  
  67. PS C:WINDOWSsystem32> ping 20.1.1.2
  68.  
  69. Pinging 20.1.1.2 with 32 bytes of data:
  70. Reply from 20.1.1.2: bytes=32 time=82ms TTL=255
  71. Reply from 20.1.1.2: bytes=32 time=15ms TTL=255
  72.  
  73. PS C:WINDOWSsystem32>
  74.  
  75. R2#show run
  76. Building configuration...
  77.  
  78. Current configuration : 799 bytes
  79. !
  80. version 12.2
  81. service timestamps debug uptime
  82. service timestamps log uptime
  83. no service password-encryption
  84. !
  85. hostname R2
  86. !
  87. aaa new-model
  88. enable secret 5 $1$R2nC$rmtvQxH1Qy6I5UpDQwA5N/
  89. !
  90. username cisco password 0 cisco
  91. memory-size iomem 15
  92. ip subnet-zero
  93. !
  94. !
  95. no ip domain-lookup
  96. ip domain-name rtp.cisco.com
  97. !
  98. ip audit notify log
  99. ip audit po max-events 100
  100. !
  101. call rsvp-sync
  102.  
  103. interface FastEthernet0/0
  104. ip address 20.1.1.2 255.0.0.0
  105. duplex auto
  106. speed auto
  107. !
  108.  
  109. line vty 0 4
  110. transport input ssh
  111. !
  112. end
  113.  
  114. R2#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement