How do I Use PowerShell to Check if an Office 365 Domain is Federated?

This article provides a step-by-step guide on how to use PowerShell to determine if a domain in Office 365 (O365) is configured for federation. Federation in Office 365 allows for shared authentication with another identity provider (IdP). This is particularly useful for organizations looking to enable single sign-on (SSO) for their users using the SurePassID ADFS plug in or our SAML IdP for O365 for examples.


Pre-requisites:
1. Admin Credentials: You must have Office 365 admin credentials to perform these checks.
2. PowerShell Environment: Ensure you have Windows PowerShell installed on your system.
3. MSOnline Module: The MSOnline PowerShell module should be installed for Office 365 administration.

  1. Open PowerShell:
    - Launch Windows PowerShell on your computer. You can do this by searching for PowerShell in your start menu and selecting the appropriate result.
  2. Install the MSOnline Module (if not already installed):**
       - Run the following command to install the MSOnline module:
         ```powershell
         Install-Module MSOnline
         ```
       - If prompted to trust the repository, type `Y` and press Enter.
  3. Connect to Office 365:
       - Execute the following command to connect to your Office 365 admin account:
         ```powershell
         Connect-MsolService
         ```
       - A login prompt will appear. Enter your Office 365 admin credentials.
  4. Check for Federation:
       - To check if a specific domain is federated, use the following command, replacing `yourdomain.com` with the domain you want to check:
         ```powershell
         Get-MsolDomainFederationSettings -DomainName yourdomain.com
         ```
       - This command will return the federation settings for the specified domain. If the domain is federated, you will see details such as the FederationBrandName, ActiveLogOnUri, PassiveLogOnUri, and other relevant information.
  5. Interpreting the Results:
       - If the domain is federated, the output will include various federation parameters.
       - If the domain is not federated, you may receive an error indicating that the domain is either not found or not federated.
  6. Disconnect from Office 365:
       - After completing your checks, it's a good practice to disconnect from the Office 365 session. Use the following command:
         ```powershell
         Disconnect-MsolService
         ```

    Troubleshooting Tips:
    - Module Installation Issues: If you encounter issues installing the MSOnline module, ensure that your PowerShell session is running with administrative privileges.
    - Connection Problems: Ensure that your internet connection is stable and that you are using the correct admin credentials.
    - Error Messages: Carefully read any error messages that appear. They often provide insights into what might be going wrong.

    Conclusion:
    Checking if an Office 365 domain is federated using PowerShell is a straightforward process that can be invaluable for IT administrators managing single sign-on and identity federation. Always ensure that you are operating in a secure environment and handling administrative credentials with care.

    References:
    - [Connect to Office 365 PowerShell](https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell)
    - [Manage Office 365 with PowerShell](https://docs.microsoft.com/en-us/office365/enterprise/powershell/manage-office-365-with-powershell)