ExchangeOnline with PowerShell 7

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Posts: 1
Last visit: Thu May 19, 2022 9:07 am

ExchangeOnline with PowerShell 7

Post by bgalinsky »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2022
Operating system: Windows 10,11
PowerShell version(s): 7.2.3

*** Please add details and screenshots as needed below. ***


Greetings all,

I have reviewed several posts regarding this topic. I'm posting because some of the replies appear contradictory (at least to me :? ).

My question is fairly straightforward. With the latest version of the ExchangeOnlineManagement module (version 2.0.5), can you display a form (GUI) first and then connect to ExchangeOnline (using the Connect-ExchangeOnline cmdlet)?

I have tried this and it hangs after the banner is displayed. As mentioned in other posts, this scenario described above used to work in WindowsPowerShell 5.1 with the ExchangeOnlineManagement version 2.0.3. It doesn't seem to work with any version above that. Some posts have suggested this does work with PowerShell 7.

Any guidance or clarification will be greatly appreciated.
User avatar
Site Admin
Posts: 1132
Last visit: Thu Jun 30, 2022 9:31 am
Answers: 25
Been upvoted: 20 times

Re: ExchangeOnline with PowerShell 7

Post by brittneyr »

[Topic moved to PowerShell GUIs forum by moderator]
Brittney Ryn
SAPIEN Technologies, Inc.
Posts: 15221
Last visit: Wed Jun 29, 2022 5:42 pm
Answers: 23
Has voted: 4 times
Been upvoted: 21 times

Re: ExchangeOnline with PowerShell 7

Post by jvierra »

Most Azure and "online" products require connection and loading of modules before you display any form. This is mostly due to the "single-threaded" nature of PowerShell. Most APIs rely on being able to control a thread completely until the connection operation is completed. Forms and GUIs tend to disrupt this and cause failures in online connective processes.

This is a condition that Microsoft has not addressed and likely won't as PowerShell was never designed to be implemented as a GUI. It can be used but certain things will not work from within a displayed form. These things can be overcome if you use a compiled program that can be multi-threaded. PowerShell cannot be multi-threaded even though we can create new threads.

My experience with the Exchange module is that it will not work correctly if it is not connected before the GUI is displayed.