我想輸出下面的命令在PowerShell中的文本文件,但我似乎無法文本文件來得到它的工作:輸出ssh命令在PowerShell中
ssh -v [email protected] | Out-File C:\output.txt
我想輸出下面的命令在PowerShell中的文本文件,但我似乎無法文本文件來得到它的工作:輸出ssh命令在PowerShell中
ssh -v [email protected] | Out-File C:\output.txt
與使用原生的post below規定應用程序,你可以嘗試使用Start-Process,例如
Start-Process ssh "-v [email protected]" -NoNewWindow -RedirectStandardOutput stdOut.log -RedirectStandardError stdErr.log; gc *.log; rm *.log
在我在我的博客How to SSH from Powershell Using Putty\Plink但短期的版本做了一個詳細的崗位同樣的問題,工作是這段代碼。但是,確保在安裝膩子後嘗試使用它。
Function Invoke-SSHCommands {
Param($Hostname,$Username,$Password, $CommandArray, $PlinkAndPath, $ConnectOnceToAcceptHostKey = $true)
$Target = $Username + '@' + $Hostname
$plinkoptions = "-ssh $Target -pw $Password"
#Build ssh Commands
$remoteCommand = ""
$CommandArray | % {$remoteCommand += [string]::Format('{0}; ', $_) }
#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
}
$PlinkAndPath = "C:\Program Files (x86)\PuTTY\plink.exe"
$Username = "remoteshell"
$Password = "pa$$w0rd"
$Hostname = "Linuxhost"
$Commands = @()
$Commands += "ls"
$Commands += "whoami"
Invoke-SSHCommands -User $Username -Hostname $Hostname -Password $Password -PlinkAndPath $PlinkAndPath -CommandArray $Commands
您的命令是否生成任何輸出? – guillermooo 2011-04-01 15:52:24
是的,我們需要更多的信息來幫助你解決這個問題。 – JasonMArcher 2011-04-03 03:42:41