PsScriptPad - Error when running Connect-Exchangeonline

Since around September 2021 I haven't been able to run Connect-Exchangeonline in PsScriptPad. It will put out the error message "Exception has been thrown by the target of an invocation.".
The command works fine in Powershell and Powershell ISE. I've tested this on multiple computers, All with the same error.

I've reinstalled ExchangeOnlineManagement multiple times with the same results.

I can open an issue for this. It’s the first I’m hearing of this problem. This cmdlet was problematic for PowerShell Universal as well.

Hi @Goldfinger147, I’m not able to recreate this at the moment but can you try uninstalling the current version of ExchangeManagementOnline and downgrading temporarily to 2.0.3?

Apparently 2.0.4 introduced breaking changes for some applications.

Note: In my recollection, installing multiple versions of this module side-by-side will not work. 2.0.4 or above cannot be available anywhere for that instance of PowerShell.

I removed 2.0.4 and installed 2.0.3 and am getting the same results.
I also tried 2.02, 2.0.5 and 2.0.6preview3. All with the same exception error.

All the machines I try it on are running Windows 10 ver. 20H2 .

Update : Also just tested with windows 11 and it still gives the same error in PsScriptPad.

Tried running on a freshly built Windows 10 machine with nothing installed, except for PsScriptPad, and I still get the exception error.

The “Exception has been thrown by the target of an invocation.” happens when running connect-exchangeonline on any Windows 10 or 11 machine I test, Whether it’s an old imaged machine or new. But, on all of them the cmdlet works fine in Powershell or Powershell ISE, just not PsScriptPad.

@DataTraveler - Let’s open an issue for this. It seems like a bug.

@Goldfinger147 - Can you try running the cmdlet in the integrated environment? I have a feeling this problem is happening due to how PS versions are opened outside of the local one.

If I select Windows Powershell (Integrated -x64) and run connect-exchangeonline I get the below message.

PS C:\Users*\Desktop> connect-ExchangeOnline : The ‘connect-ExchangeOnline’ command was found in the module ‘ExchangeOnlineManagement’, but **
the module could not be loaded. For more information, run ‘Import-Module ExchangeOnlineManagement’.
At line:1 char:1
+ connect-ExchangeOnline
**+ ~~~~~~~~~~~~~~~~~~~~~~
*
** + CategoryInfo : ObjectNotFound: (connect-ExchangeOnline:String) [], CommandNotFoundException**
** + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule**

If I run Import-Module ExchangeOnlineManagement I get this error.

PS C:\Users*\Desktop> Import-Module ExchangeOnlineManagement*
PS C:\Users*\Desktop> Import-Module : The member ‘FileList’ in the module manifest is not valid: The path is not of a legal form… Verify **
**that a valid value is specified for this field in the 'C:\Program **
Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\ExchangeOnlineManagement.psd1’ file.
At line:1 char:1
+ Import-Module ExchangeOnlineManagement
**+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
** + CategoryInfo : ResourceUnavailable: (C:\Program File…Management.psd1:String) [Import-Module], **
ArgumentException
** + FullyQualifiedErrorId : Modules_InvalidManifest,Microsoft.PowerShell.Commands.ImportModuleCommand**

1 Like

Hello, Will I get a notification when a issue is open for this problem?

This issue is being tracked here and will be included in our April release cycle.

Hello, The ticket shows as completed but after updating PsScriptpad to the latest version today, it still gives the error “Exception has been thrown by the target of an invocation.”

Hey @Goldfinger147 ,

Apologies. This fix wasn’t merged in for some reason before release. I’ve merged it in and release 2022.4.1.

https://psscriptpad.blob.core.windows.net/releases/PSScriptPad.x86.2022.4.1.zip

It does work but only partially now. After entering my logon information it gets stuck for awhile and then gives the error “The background process reported an error with the following message: “The named pipe target process has ended.””.