# E365-Mailbox-ConvertToShared.ps1

  • Purpose
  • Dependencies
  • Function
  • Usage
  • Inputs
  • Variables
  • Command Line Flags
  • Outputs
  • Notes

# Purpose

Intended for hybrid environemnts - this script performs multiple actions to assist in mailbox cleanups, primarily when a user departs the organisation.

Specifically - it converts a user mailbox to a shared mailbox in Exchange Online (E365). Confirms user existence, matches on multiple AD attributes, connects to both on-prem and cloud Exchange, and performs the conversion interactively.

# Dependencies

  • Active Directory module (Microsoft Docs)
  • Exchange Online Management module (Microsoft Docs)
  • Windows Forms (part of .NET, used for pop-up feedback)

# Function

  1. Prompts for the user to convert (accepts login, UPN, email, or display name).
  2. Searches AD for the user by SamAccountName, UserPrincipalName, EmailAddress, or Name.
  3. Connects to on-prem Exchange and hides the mailbox from the GAL.
  4. Connects to Exchange Online (cloud) and converts the mailbox to shared.
  5. Provides pop-up and console feedback at each step.

# Usage

./E365-Mailbox-ConvertToShared.ps1

The script is fully interactive and does not require command-line parameters for standard use. It prompts for user input and guides the admin through the process.

# Inputs

  • User input via prompt: login, UPN, email, or display name of the mailbox to convert

# Variables

  • $SamAccountNameFrom: The matched user's SamAccountName
  • $orgUnitLocationFrom: The matched user's AD distinguished name
  • $scriptComplete: Script completion flag

# Command Line Flags

None for standard use.

# Outputs

  • Converts the specified mailbox to shared in Exchange Online
  • Hides the mailbox from the GAL in on-prem Exchange
  • Provides pop-up and console feedback for each step

# Notes

  • Requires the Active Directory and Exchange Online Management modules
  • GUI-based pop-ups require Windows Forms
  • Script provides clear error messages and instructions for each step