Powershell script to check whether Mailboxes are in Exchange servers or not.

Wonderwhy 171 Reputation points
2022-05-30T04:16:04.67+00:00

Exchange Server 2016 On-premise and M365 Hybrid.

I want to know how to check whether Mailboxes are in Exchange servers or not by Get-Mailbox command.

User Number : Over 100 users

I have User's ID number as a txt.
Would you please tell me how to make PS1 script to export the result of 'Get-Mailbox" for these above Mailboxes, it's CSV or txt to save the files into C:¥temp.

Kind regards,

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Exchange | Exchange Server | Management
Exchange | Exchange Server | Management
The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.
Exchange | Hybrid management
Exchange | Hybrid management
The administration of a hybrid deployment that connects on-premises Exchange Server with Exchange Online, enabling seamless integration and centralized control.
0 comments No comments
{count} votes

Answer accepted by question author
  1. KyleXu-MSFT 26,396 Reputation points
    2022-05-31T02:07:14.587+00:00

    @Wonderwhy

    What do you mean about "User's ID number"? Do you mean "ExchangeGuid"? If not, could you explain about it and where it from?

    If so, you could use a source file like below:

    206875-qa-kyle-10-04-05.png

    Then use the script below to check them (Save it to a ".ps1" file, then run it in EMS):

    $users= Import-Csv c:\temp\users.csv  
    $Result= @()  
      
    foreach($user in $users){  
        if (Get-Mailbox $user.ExchangeGuid -ErrorAction SilentlyContinue){  
            $temp = Get-Mailbox $user.ExchangeGuid | select Name,ServerName,@{Expression={$_.ExchangeGuid};Label="ExchangeGuid";}   
            $Result+=$temp  
        }  
    }$Result | Export-Csv c:/temp/LocalMailbox.csv -NoTypeInformation  
    

    It will export the Exchange on-premises mailbox to the "LocalMailbox.csv"


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

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