New-SSHSession : Sequence contains more than one element

Open
#182 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
powershell
Domain
cli

Research direction

Start with the supplied Adjust-gslb function and its New-SSHSession call, then inspect how the Posh-SSH command handles the PSCredential created by Get-Credential. Reproduce the reported error with the two NetScaler addresses and compare it with the hardcoded credential case. Done means the credential-passing behavior and the source of the multiple-element error are identified and covered by an appropriate regression check.

Written by the indexing model from the issue text.

Description

I am getting the below error when trying to use get-credential in my script and passing $creds to a function. If I hardcode nsuser and nspass in the script this works fine. Any help is much appreciated

New-SSHSession : Sequence contains more than one element At N:\scripts\Netscaler\Adjust-NS-GSLB\Adjust-NS-GSLB-v3.1.ps1:54 char:2 + New-SSHSession -computername $nsip -Credential $creds -acceptKey ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Renci.SshNet.SshClient:SshClient) [New-SSHSession], InvalidOperationException + FullyQualifiedErrorId : SSH.NewSshSession

Here is the script that I am using

#---------------------
Function Adjust-gslb {
[Parameter(Mandatory = $true)]
param (
$nsips = [string]$nsips,
$Creds = [string]$Creds,
$ns_cmd = [string]$nsremove
)
$Creds = New-Object System.Management.Automation.PSCredential ($nsuser, $nspass)
Write-Host "Adjust_GSLB Function - Adjusting $ns_cmd" -ForegroundColor cyan
foreach($nsip in $nsips){
Get-SSHSession | Remove-SSHSession | Out-Null
New-SSHSession -computername $nsip -Credential $creds -acceptKey | out-null
$temp2 = (Invoke-SSHCommand -index 0 -command "$ns_cmd")
}
remove-sshsession -index 0 | out-null
}
#----------------------
#Main Script
$nsips = "1962.168.2.52","192.168.54.25"
$nsremove = "bind gslb vserver stuff -servername MyStuff"
$mycred = Get-Credential -UserName $env:username -Message "Enter in your UID and PWD for the NS"
$nsuser = $mycred.username
$nspass = $mycred.password
$Creds = New-Object System.Management.Automation.PSCredential ($nsuser, $nspass)

Adjust-gslb -nsips $nsips -creds $Creds -ns_cmd $nsremove

Dominant language
PowerShell
Stars
1.1k
Forks
222
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from darkoperator/Posh-SSH

All issues in darkoperator/Posh-SSH

Similar issues

More CLI issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.