Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property #21551

Open
5 tasks done
msekkappan opened this issue Apr 29, 2024 · 11 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@msekkappan
Copy link

Prerequisites

Steps to reproduce

Running these commands in interactive mode works perfectly. However, saving them to a file and running them throws this error.

format-default: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was:

Connect-MicrosoftTeams
$AllTeams = Get-Team -User JXXXXXX@XXXXX.OnMicrosoft.com
$AllTeams

Expected behavior

Should display all the teams that the user is a member of.

Actual behavior

Error
format-default: There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was:

Error details

Type           : System.Management.Automation.CmdletInvocationException

ErrorRecord    :

    Exception             :

        Type       : System.NullReferenceException

        TargetSite :

            Name          : Inject

            DeclaringType : System.Management.Automation.Internal.PipelineProcessor, System.Management.Automation,

Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35

            MemberType    : Method

            Module        : System.Management.Automation.dll

        Message    : Object reference not set to an instance of an object.

        Source     : System.Management.Automation

        HResult    : -2147467261

        StackTrace :

   at System.Management.Automation.Internal.PipelineProcessor.Inject(Object input, Boolean enumerate)

   at System.Management.Automation.Internal.PipelineProcessor.Step(Object input)

   at Microsoft.PowerShell.Commands.Internal.Format.OutputManagerInner.ProcessRecord()

   at Microsoft.PowerShell.Commands.OutDefaultCommand.ProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

    CategoryInfo          : NotSpecified: (:) [Out-Default], NullReferenceException

    FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.OutDefaultCommand

   InvocationInfo        :

        MyCommand       : Out-Default

        HistoryId       : 3

        InvocationName  : Out-Default

        CommandOrigin   : Internal

    ScriptStackTrace      : at <ScriptBlock>, C:\temp\Test.ps1: line 18

                            at <ScriptBlock>, <No file>: line 1

    PipelineIterationInfo :

 

 

 

Message        : Object reference not set to an instance of an object.

InnerException :

    Type       : System.NullReferenceException

    TargetSite :

        Name          : Inject

        DeclaringType : System.Management.Automation.Internal.PipelineProcessor, System.Management.Automation,

Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35

        MemberType    : Method

        Module        : System.Management.Automation.dll

    Message    : Object reference not set to an instance of an object.

    Source     : System.Management.Automation

    HResult    : -2147467261

    StackTrace :

   at System.Management.Automation.Internal.PipelineProcessor.Inject(Object input, Boolean enumerate)

   at System.Management.Automation.Internal.PipelineProcessor.Step(Object input)

   at Microsoft.PowerShell.Commands.Internal.Format.OutputManagerInner.ProcessRecord()

   at Microsoft.PowerShell.Commands.OutDefaultCommand.ProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

HResult        : -2146233087

Environment data

Name                           Value

----                           -----

PSVersion                      7.4.1

PSEdition                      Core

GitCommitId                    7.4.1

OS                             Microsoft Windows 10.0.19045

Platform                       Win32NT

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}

PSRemotingProtocolVersion      2.3

SerializationVersion           1.1.0.1

WSManStackVersion              3.0

Visuals

No response

@msekkappan msekkappan added the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 29, 2024
@msekkappan
Copy link
Author

Version 7.4.2 behaves the same.

@mklement0
Copy link
Contributor

So you're saying that saving the commands to a .ps1 file and invoking that file from a stand-alone PowerShell session produces this symptom? Or are you executing the file via the PowerShell SDK (e.g. from a C# project)?

@msekkappan
Copy link
Author

msekkappan commented Apr 30, 2024 via email

@msekkappan
Copy link
Author

Saving these in a ps1 file and invoking in a PS Console throws this error message. If I type these commands individually in the console it does not happen.

@mklement0
Copy link
Contributor

The error comes from the display-formatting system, but the error message is usually only seen when PowerShell is hosted in other applications.
Also, the error details describe a different error, "Object reference not set to an instance of an object."

Your symptom suggests that execution - and therefore joint formatting - in a single pipeline may trigger the bug, so see if the following makes a difference:

Connect-MicrosoftTeams | Out-Host  # force instant, direct-to-display output
$AllTeams = Get-Team -User JXXXXXX@XXXXX.OnMicrosoft.com
$AllTeams

@msekkappan
Copy link
Author

msekkappan commented May 2, 2024 via email

@msekkappan
Copy link
Author

msekkappan commented May 3, 2024 via email

@msekkappan
Copy link
Author

msekkappan commented May 3, 2024 via email

@mklement0
Copy link
Contributor

Thanks; personally, I can't be of further assistance, because I don't have access to Microsoft Teams, but I hope someone else can help you narrow this down.

@kilasuit
Copy link
Collaborator

kilasuit commented May 4, 2024

I believe this to be an issue with the MicrosoftTeams module more than PowerShell
Please can you provide which version of the module you are using from Get-Module MicrosoftTeams as this was missed from your inital repro steps

@msekkappan
Copy link
Author

msekkappan commented May 6, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

3 participants