Debugger seems to break "Invoke-Command"

Product: PowerShell Universal
Version: 2.8.2

I have a bunch of scripts that connect to a remote Exchange server.
With a recent update of PSU to version 2.8.0, those scripts stopped working. Updating to 2.8.2 does not solve it.

$pssession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://exchange-server-hostname-redacted/PowerShell" -verbose   

    $mailboxObject = Invoke-Command -Session $pssession -ScriptBlock {Get-Mailbox "some-mailbox-name" }
Remove-PSSession -Id $pssession.Id
   - System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerShell.Commands.InvokeCommandCommand.GetHostDebugger()
   at Microsoft.PowerShell.Commands.InvokeCommandCommand.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin() 

The code causing the null reference exception is the function GetHostDebugger(), for which the source code can be found here:

Could it be that either “InternalHost” or “Runspace” are null, from within the context in PSU?
If I run the same script from a normal Powershell prompt, it runs fine.

I noticed this the other day and I’m not sure why this is happening yet. Sorry for the issue.

Thanks for your quick reply @adam !
I’ll keep an eye on this thread and on the GitHub post for a solution.

We’re you running 2.7 before this?

Never mind. I’ve isolated the issue.

1 Like

We’ve rolled out 2.8.3 today and the issue was fixed. Thanks @adam !

1 Like