The window closes automatically when connect to Exchange Online with PowerShell

GRS 0 Reputation points
2024-07-25T01:27:35.45+00:00

In order to change some of the organization's settings, I entered these commands in PowerShell one after the other. I don't know if there was a successful connection to Exchange Online PowerShell. But as soon as the last command is lost, the PowerShell window closes automatically.

Set-ExecutionPolicy RemoteSigned

Install-Module -Name ExchangeOnlineManagement

Import-Module ExchangeOnlineManagement

Connect-ExchangeOnline

User's image

In the pop-up window, enter the account number (administrator ) and password

User's image

Then this screen appeared, and it didn't tell me if the connection was successful.

Finally, I ran Get-AcceptedDomain to test, and the command ran for about 1 second, and there was no feedback, and the PowerShell window closed automatically!!!???

Hello, may I ask why is this? Is it because I'm doing something incorrectly? Is there any workaround? Thank you very much.

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,124 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,578 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,595 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Zhang-MSFT 1,840 Reputation points Microsoft Vendor
    2024-07-25T07:30:20.6733333+00:00

    Hello, @GRS,

     

    Welcome to the Microsoft Q&A platform!

     

    Based on your description, I understand that you want to run some commands in PowerShell, but you can't know if the connection is successful and why the window closes automatically. However, I want to share the following with you. The screenshot you offered above shows that you have successfully connected. Also, the Get-AcceptedDomain works successfully in my test as below.

    User's image

    Therefore, please kindly refer to steps of  Connect to Exchange servers using remote PowerShell | Microsoft Learn to see if there are anything missed.

    Also, I suggest you could change another command to test such as Get-Mailbox to see if the window disappears as well.

     

    Looking forward to your update and please feel free to contact me if you have any queries.

    If my reply is helpful to you, please mark it as the answer so that other users can refer to it. Thank you for your support and understanding.

     

    Best,

    Alex Zhang


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.