plink使用方法 linux,Vmware SSH PowerShell 技巧与plink.exe

最近我需要执行一些PowerCLI的行动,从ESXi Shell中,你可知道,目前还没有从的cmdlet允许您运行shell命令,但这是流行在社区内的一个选项是使用第三方工具,称为砰砰。exe来运行通过SSH命令。

下载plink.exe通过PowerShell。

我在写脚本的人谁,我不知道已经有安装砰砰,我想他们很少有使用该脚本时没有力气,所以我想分享的第一招是能够检查plink.exe下载它,如果它不是在同一个目录中的脚本,这可以看出如下:

$myDir = Split-Path -Parent $MyInvocation.MyCommand.Path

$PlinkLocation = $myDir + "\Plink.exe"

If (-not (Test-Path $PlinkLocation)){

Write-Host "Plink.exe not found, trying to download..."

$WC = new-object net.webclient

$WC.DownloadFile("~sgtatham/putty/latest/x86/plink.exe",$PlinkLocation)

If (-not (Test-Path $PlinkLocation)){

Write-Host "Unable to download plink.exe, please download from the following URL and add it to the same folder as this script: ~sgtatham/putty/latest/x86/plink.exe"

Exit

} Else {

$PlinkEXE = Get-ChildItem $PlinkLocation

If ($PlinkEXE.Length -gt 0) {

Write-Host "Plink.exe downloaded, continuing script"

} Else {

Write-Host "Unable to download plink.exe, please download from the following URL and add it to the same folder as this script: ~sgtatham/putty/latest/x86/plink.exe"

Exit

}

}

}

Accept plink.exe host key automatically

Secondly when connecting to a host for the first time you will need to

accept the host key and allow plink.exe to connect to the host, the

message is similar to the one below:

uid-26893608-id-4038902.html

At the moment there is no option in plink.exe to skip the host key

checking, however after some searching and messing around I came upon a

solution.

It turns out you can actually send a Y to the script you are running by

simply piping “echo Y” to plink.exe, this sends a Y accepting the host

key when the question is asked from the command line, this can be

scripted like the below example:

Echo Y | Plink.exe…..

Hopefully someone will find these useful in the future as I did with this script.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值