question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke-Command -SSHConnection breaks if the HostName string is [psobject]-wrapped

See original GitHub issue

The root cause is that a string returned from a cmdlet call or external program has an invisible extra [psobject] wrapper, and the Invoke-Command cmdlet fails to take that possibility into account.

In short: The command below breaks, because (hostname) has such an invisible wrapper, as evidenced by (hostname) -is [psobject] being $true.

This is yet another manifestation of our old friend #5579.

The specific problem in Invoke-Command is here.

Steps to reproduce

{ icm -SSHConnection @{ Hostname = (hostname) } -ScriptBlock { 'hi' }  } | 
  Should -not -Throw

Expected behavior

The test should succeed, if the local computer is set up for being a SSH remoting target.

Actual behavior

The test fails:

Expected no exception to be thrown, but an exception 
"The provided SSHConnection hashtable parameter name or element is null or empty." was thrown from line:1 char:3

Note that using (hostname).psobject.BaseObject or "$(hostname)" or (hostname).ToString() makes the problem go away.

As an aside: if the host name were truly invalid due not being a string, the error message would be misleading, because the problem is that the entry is of the wrong type, not that it is null or empty.

A further aside: The comment above the SSHConnection parameter definition is incomplete: keys Port and Subsystem are missing.

Environment data

PowerShell Core v7.0.0-preview.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SeeminglySciencecommented, Oct 3, 2019

@iSazonov Yeah I can grab it

1reaction
iSazonovcommented, Oct 3, 2019

@SeeminglyScience Can you grab this? I already have over 15 opened PRs but I’d prefer to get the null reference exception fixed before GA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found