通过Powershell运行Plink.exe

时间:2014-06-12 06:59:29

标签: powershell plink

我需要编写一个将连接到plink.exe命令行工具的powershell脚本,它必须使用powershell提供的IP地址打开远程服务器。 我尝试的脚本没有向我显示任何错误,但它也无法连接到plink。 代码如下所述,任何人都可以告诉我哪里出错 -

function plink
{
  [CmdletBinding()]
  PARAM
  (
    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $remoteHost,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $login,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $passwd,

    [Parameter(Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string] $command)

  & "D:\plink.exe" -ssh $remoteHost -l $login -pw $passwd $command
  return
}

$remoteHost = "172.21.3.185"
$login = "exchangelab/admin"

$command1 = "/opt/compiere/apache-tomcat-6.0.32/bin/shutdown.sh "
$command2 = "cd /opt/compiere/apache-tomcat-6.0.32/bin && ./startWS.sh"
$command3 = "ps -edalf | grep java"

$passwd = Read-Host "Enter Password for $login" 

如何在程序中调用plink函数? 谢谢。

1 个答案:

答案 0 :(得分:0)

您已声明了一个函数并且您已声明了变量,但您尚未通过调用该函数将其中任何一个置于行动中。如果这个答案没有意义,我建议您进一步阅读:Powershellpro.com function tutorial