Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PS C:WINDOWSsystem32> Function Invoke-SSH
- {
- Param($Hostname,$Username,$Password,$CommandArray,$PlinkAndPath,
- $ConnectOnceToAcceptHostKey = $true)
- $Target = $Username + '@' + $Hostname
- $plinkoptions = "-ssh $Target -pw $Password"
- $CommandArray | % {$remoteCommand += $Commands}
- #plist prompts to accept client host key. This section will
- login and accept the host key then logout.
- if($ConnectOnceToAcceptHostKey)
- {
- $PlinkCommand = [string]::Format('echo y | & "{0}" {1}
- exit',$PlinkAndPath, $plinkoptions )
- #Write-Host $PlinkCommand
- $msg = Invoke-Expression $PlinkCommand
- }
- #format plist command
- $PlinkCommand = [string]::Format('& "{0}" {1} "{2}"',
- $PlinkAndPath,$plinkoptions , $remoteCommand)
- #ready to run the following command
- #Write-Host $PlinkCommand
- $msg = Invoke-Expression $PlinkCommand
- $msg | Out-File -FilePath
- C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTest
- DeLoAutoLog.txt -Append
- }
- #Plink path, credentials and target server definition
- $PlinkAndPath
- = "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTestplink.exe"
- $Username = "cisco"
- $Password = "cisco"
- $Hostname = "20.1.1.2"
- #Commands to execute on the remote ssh host.
- $Commands += "show version"
- Output:
- Invoke-SSH -User $Username -Hostname $Hostname -Password $Password
- -PlinkAndPath $PlinkAndPath -CommandArray $Commands
- plink.exe : FATAL ERROR: SSH protocol version 2 required by configuration
- but not provided by server
- At line:1 char:10
- + echo y | & "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTes ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : NotSpecified: (FATAL ERROR: SS...vided by
- server:String) [], RemoteException
- + FullyQualifiedErrorId : NativeCommandError
- plink.exe : FATAL ERROR: SSH protocol version 2 required by configuration
- but not provided by server
- At line:1 char:1
- + & "C:UsersadminDesktopDevice_Logs_AutomationDeLoAutoTestplink.e ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : NotSpecified: (FATAL ERROR: SS...vided by
- server:String) [], RemoteException
- + FullyQualifiedErrorId : NativeCommandError
- PS C:WINDOWSsystem32> ping 20.1.1.2
- Pinging 20.1.1.2 with 32 bytes of data:
- Reply from 20.1.1.2: bytes=32 time=82ms TTL=255
- Reply from 20.1.1.2: bytes=32 time=15ms TTL=255
- PS C:WINDOWSsystem32>
- R2#show run
- Building configuration...
- Current configuration : 799 bytes
- !
- version 12.2
- service timestamps debug uptime
- service timestamps log uptime
- no service password-encryption
- !
- hostname R2
- !
- aaa new-model
- enable secret 5 $1$R2nC$rmtvQxH1Qy6I5UpDQwA5N/
- !
- username cisco password 0 cisco
- memory-size iomem 15
- ip subnet-zero
- !
- !
- no ip domain-lookup
- ip domain-name rtp.cisco.com
- !
- ip audit notify log
- ip audit po max-events 100
- !
- call rsvp-sync
- interface FastEthernet0/0
- ip address 20.1.1.2 255.0.0.0
- duplex auto
- speed auto
- !
- line vty 0 4
- transport input ssh
- !
- end
- R2#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement