0
我有这个powershell命令,我用它来打开一个kitty/PuTTY会话。 格式是Powershell访问命令行参数
.\my_sshCommand three
在这种情况下,应该带我去server.three,但无论我把什么命令行参数在需要我来server.TWO。这个想法是,如果命令行中没有参数,那么server.TWO将是默认值。我真的不知道如何在PowerShell中进行循环,所以我只是硬编码了这些命令。我不知道为什么命令总是满足else子句,无论我在脚本中放入了什么命令行参数。
param(
[array] $ComputerName
)
ForEach ($Computer in $ComputerName) {
IF($Computer -match 'one') {
$Computer="server.one"
Write-Output "c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
$Command="c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
}
IF($Computer -match 'two') {
$Computer="server.TWO"
Write-Output "c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
$Command="c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
}
IF($Computer -match 'three') {
$Computer="server.three"
Write-Output "c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
$Command="c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
}
IF($Computer -match 'four') {
$Computer="server.four"
Write-Output "c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
$Command="c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected]$Computer -pw pizza"
}
ELSE {
Write-Output "c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected] -pw pizza"
$Command="c:\Working\Kitty.exe -load `"capser profile`" -ssh [email protected] -pw pizza"
}
}
Invoke-Expression $Command