Background
Shared mailboxes, conference rooms, equipment mailboxes, and O365 groups are widely used within Exchange Online. As a result, end users can sometimes have a hard time tracking down the proper resource when searching in the GAL. Using a naming standard for each resource type, shared mailbox, conference room, equipment mailbox, and O365 group can greatly reduce confusion for end users when trying to find the right resource.
Solution
The naming standard script will add a prefix to any shared mailbox, conference room, equipment mailbox, or O365 group allowing these objects to be organized together in the GAL. The script needs to be executed on a daily basis to ensure new resource types are updated accordingly.
In order to get the script to execute in your Exchange Online organization, perform the following steps prior to script execution.
- Create a folder named Temp under C:\
- Create a folder named Naming Standard under C:\Temp
- Create a folder named Log under C:\Temp\Connect
- Create a folder named Cred under C:\Temp\Connect
- Change line 3 in the code to your administrative account name
- When your password changes, you will need to delete the cred.txt file under C:\Temp\Naming Standard\Cred
- The account must have administrative privileges for services in Office 365
Note: Load the PowerShell Script in PowerShell ISE to match line numbers.
Results
The output below illustrates the displayname of resource mailboxes before running the naming standard script.
Shared Mailbox Before
O365 Group Before
Room Mailbox Before
Equipment Mailbox Before
The output below illustrates the displayname of the resource mailboxes after running the naming standard script.
Shared Mailbox After
O365 Group After
Room Mailbox After
Equipment Mailbox After
The objects are now listed together in the GAL
Script
$logfile = ("C:\Temp\Naming Standard\Log\NamingStandard.log")
$PasswordFile = "C:\Temp\Naming Standard\Cred\cred.txt"
$AdminAccount = "admin@domain.onmicrosoft.com"
#Naming standard for group types
$PrefixEQ = "EQ-"
$PrefixRM = "RM-"
$PrefixShared = "Shared-"
$PrefixO365 = "O365-"
#Log file function
function log{
param (
[String]$text,
[Switch]$fout
)
ac $logfile $text
if($showConsoleOutput){
if($fout){
Write-Host $text -ForegroundColor Red
}else{
Write-Host $text -ForegroundColor Green
}
}
}
log -text "-----$(Get-Date) Services - $($env:USERNAME) on $($env:COMPUTERNAME) starting-----"
#Check password file
$PasswordFileCheck = Test-Path $PasswordFile
If($PasswordFileCheck -eq $False){
Read-Host -Prompt "Enter Admin Password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\Temp\Naming Standard\Cred\cred.txt"
log -text "Created a password file under C:\Temp\Naming Standard\Cred"
}
Else{
log -text "Password file already created under C:\Temp\Naming Standard\Cred"
}
#Connect to Exchange Online
$Pass = Get-Content $PasswordFile | ConvertTo-SecureString
$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminAccount, $Pass
$Connect2 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $Cred -Authentication "Basic" -AllowRedirection -ErrorAction SilentlyContinue -ErrorVariable ProcessError
Import-PSSession $Connect2 -DisableNameChecking -AllowClobber
If ($ProcessError) {
log -text "------ Didn't Connect to Exchange Online"
}
Else{
log -text "Connected to Exchange Online"
}
#>
#Check mailbox types
$ResourceEQ = get-mailbox -ResultSize:Unlimited | Where-Object {$_.ResourceType -eq "Equipment" -and $_.Alias -notmatch "EQ"}
Foreach ($MailboxEQ in $ResourceEQ) {
$MBXEQA = $MailboxEQ.Alias
$MBXEQN = $MailboxEQ.Name
$MBXEQD = $MailboxEQ.DisplayName
$MBXEQS = $MailboxEQ.UserPrincipalName
$MBXEQA1 = "$PrefixEQ$MBXEQA"
Set-Mailbox $MBXEQA -Alias $MBXEQA1
$MBXEQN1 = "$PrefixEQ$MBXEQN"
Set-Mailbox $MBXEQA1 -Name $MBXEQN1
$MBXEQD1 = "$PrefixEQ$MBXEQD"
Set-Mailbox $MBXEQA1 -DisplayName $MBXEQD1
}
$ResourceRM = get-mailbox -ResultSize:Unlimited | Where-Object {$_.ResourceType -eq "Room" -and $_.Alias -notmatch "RM"}
Foreach ($MailboxRM in $ResourceRM) {
$MBXRMA = $MailboxRM.Alias
$MBXRMN = $MailboxRM.Name
$MBXRMD = $MailboxRM.DisplayName
$MBXRMS = $MailboxRM.UserPrincipalName
$MBXRMA1 = "$PrefixRM$MBXRMA"
Set-Mailbox $MBXRMA -Alias $MBXRMA1
$MBXRMN1 = "$PrefixRM$MBXRMN"
Set-Mailbox $MBXRMA1 -Name $MBXRMN1
$MBXRMD1 = "$PrefixRM$MBXRMD"
Set-Mailbox $MBXRMA1 -DisplayName $MBXRMD1
}
$ResourceShared = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | Where-Object {$_.Alias -notmatch "Shared"}
Foreach ($MailboxShared in $ResourceShared){
$MBXSharedA = $MailboxShared.Alias
$MBXSharedN = $MailboxShared.Name
$MBXSharedD = $MailboxShared.DisplayName
$MBXSharedS = $MailboxShared.UserPrincipalName
$MBXSharedA1 = "$PrefixShared$MBXSharedA"
Set-Mailbox $MBXSharedA -Alias $MBXSharedA1
$MBXSharedN1 = "$PrefixShared$MBXSharedN"
Set-Mailbox $MBXSharedA1 -Name $MBXSharedN1
$MBXSharedD1 = "$PrefixShared$MBXSharedD"
Set-Mailbox $MBXSharedA1 -DisplayName $MBXSharedD1
}
#Get a list of O365 groups
$O365Group = Get-UnifiedGroup -ResultSize:unlimited | Where-Object {$_.Alias -notmatch "O365"}
Foreach ($Group in $O365Group) {
$GroupN = $Group.Name
$GroupA = $Group.Alias
$GroupD = $Group.DisplayName
$GroupS = $Group.UserPrincipalName
IF ($Group -notmatch "O365-"){
$GroupA1 = "$PrefixO365$GroupA"
$GroupD1 = "$PrefixO365$GroupD"
Set-UnifiedGroup $GroupN -Alias $GroupA1
$GroupN1 = "$PrefixEQ$MBXD"
Set-UnifiedGroup $GroupA1 -DisplayName $GroupD1
}
}
#>