0
$resources = @()
$resources += "PC1"
$creds [email protected]()
write-host "Obtaining creds from PMP"
for ($i=0; $i -lt $resources.length; $i++) {
$creds = get-creds $resources[$i] root
}
for ($i=0; $i -lt $resources.length; $i++) {
$sessionA = $(New-SshSession -ComputerName $resources[$i] -Username root -Password $creds[$i])
if ($sessionA -match "Successfully connected") {
x
}
else
{
error
}}
我一直试图建立ssh连接时出错。 如果我回应$ resources [0]和$ creds [0]的值,我会得到正确的结果,并可以使用这些值与ssh用腻子。 如果我创建新的变量:PowerShell阵列中的字符串问题
$tes1 = $resources[0]
$test2 = $creds[0]
,并同时使用在:
$sessionA = $(New-SshSession -ComputerName $test1 -Username root -Password $test2)
它也可以...
出于某种原因,数组引用不:/
感谢您的反馈。
对不起,它只是代码的一部分。我用$ creds替换$ pass,就像它在我的代码中一样。 – Chris
仍然相同:P不喜欢我的数组字符串:/ – Chris
尝试在第二个循环中使用另一个变量作为计数器。所以,例如试一下:for($ y = 0; $ y-lt $ resources.length; $ y ++){... –