- PS Environment EXOV AD Module in script Results
- PS ISE EXOV2 Yes Works
- PS ISE EXOV2 No Works
- PS ISE EXOV3 Yes Works
- PS ISE EXOV3 No Works
- PSStudio EXOV2 Yes Works
- PSStudio EXOV2 No Works
- PSStudio EXOV3 Yes gets error list above
- PSStudio EXOV3 No Works
Operating system: Windows 10 Enterprise (64bits) 21H2 - Build: v10.0.19044.0
PowerShell version(s): 5.1
Using ExchangeOnlineManagement 3.1.0 (EXOV3) module in PowerShell Studio gets this error:
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
This error occurs with STA Mode enabled and disabled.
This does not occur in PS ISE, nor with ExchangeOnlineManagement 2.0.3 (EXOV2)
I narrowed down the issue to import-module ActiveDirectory being in the script using EXOV3 and PS Studio as the only combination that gets an error.
The ActiveDirectory module and EXOV3 are essential to my script. I'm coding a GUI therefore I need this to work in PS Studio.
I'm at the latest version of PS Studio 2023, PS 5.1.x
Here is a chart of combinations
Here is the code that does NOT work in PS Studio.
user@email.domain is in the code posted here but actual code has a real value that is valid.
Code execution fails on connect-exchangeonline and enters the catch block to display the error message.
Code: Select all
Import-Module ActiveDirectory
Import-module -Name ExchangeOnlineManagement -RequiredVersion 3.1.0
$error.Clear()
try
{
Write-Host 'logging in with user account to EXO'
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
Connect-ExchangeOnline -UserPrincipalName "user@email.domain" -ShowBanner:$false
$ErrorActionPreference = 'Continue'
$a = Get-ConnectionInformation
Write-Host "Connection ID: $($a.Id)"
Disconnect-ExchangeOnline -Confirm:$false
}
Catch
{
Write-Host $_
}
exit