Enable Unified Messaging Office 365 using PowerShell
Scenario:
Enable Unified Messaging Office 365 using PowerShell.
Unified Messaging is a feature that you have to enable through your Exchange server OnPremise or Exchange Online, on the mailbox site. The next information has been extracted from Microsoft’s website. When you deploy Unified Messaging, users can access voice mail, email, and calendar information that’s located in their mailbox from an email client, for example, Outlook or Microsoft Outlook Web App, from a mobile phone with Microsoft Exchange ActiveSync set up, such as a Windows Phone, or from a telephone.
In general the script will automatically enable Unified Messaging to all Skype for Business telephony users. I have configured the script to run on a schedule basis every night to enable Unified Messaging to all user mailboxes that they are suppose to have it enabled. The script connects on both Active Directory and Exchange Online to perform the process.
Let check what the script does in more details
First the script will retrieve the credentials that will be used through out the process. Two different credentials are used. The first one is the admin account that will connect on Office365 and enable Unified Messaging. The second account is the account that will be used to send the email reports at the end of the process. Then the script connects on Office365 and collects all users that Skype for Business telephony is enabled and adds the mailbox in a variable.
For each user that has been added in the variable, the script will check the mail value and if Unified Messaging is enabled. If Unified Messaging is not enabled the script sets some variables based on the telephony configuration of the user within Skype for Business. These variables are used later to enable Unified Messaging on the mailbox. After the feature (Unified Messaging) has been enabled, the script will check again the status of Unified Messaging and will keep it in a variable to be used in the reporting.
Reporting
After the process has been completed, the script will provide a report on which mailboxes, unified message has been enabled. The email report will include the mailbox name that there was a change on unified message , the status of unified message before and after the change. The reason that I use before and after status, is that sometimes it might be an issue while enabling unified messaging and the status will remain to false. An error report is also configured, if there are any errors or exceptions during the run of the script. All errors or exceptions will be send if there are any. If there is no change made by the script, then no email report will be send.
You can download the script here or copy it from below.
Hope you will like the script and leave your comments below. If you want to ask anything do not hesitate to contact me or comment below.
Related Links:
- Send Email using PowerShell
- Encrypt password with key using PowerShell
- Email error variable in PowerShell
- Get-Content – Microsoft Docs
- ConvertTo-SecureString – Microsoft Docs
- Creating .NET and COM Objects New Object | Microsoft Docs
- New-PSSession – Microsoft Docs
- Import-PSSession – Microsoft Docs
- Get-CsUser – Microsoft Docs
- Get-ADUser – TechNet – Microsoft
- Get-Mailbox – TechNet – Microsoft
- Get-UMMailboxPolicy – TechNet – Microsoft
- Enable-UMMailbox – TechNet – Microsoft
- Send-MailMessage – Microsoft Docs
- Get-Date – Microsoft Docs
Solution / Script:
$File = "C:\Scripts\Password_O365.txt"
$Key = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)
$AdminUser = "admin-user@company.onmicrosoft.com"
$Password = Get-Content $File | ConvertTo-SecureString -Key $Key
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminUser,$Password
$emailfile = "C:\Scripts\Password.txt"
$emailuser = "Email-User@domain.com"
$emailpassword = Get-Content $emailfile | ConvertTo-SecureString -Key $key
$EmailCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $emailuser,$emailpassword
$To = 'User1@domain.com','User2@domain.com'
$From = 'Email-User@domain.com'
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
$VoiceEnabledUsers = (get-csuser | where {($_.EnterpriseVoiceEnabled -eq "True") -and
($_.RegistrarPool.FriendlyName -eq "Lync-Server.domain.com")}).SamAccountName
foreach ($VoiceEnabledUser in $VoiceEnabledUsers) {
$UPNUser = (Get-ADUser -Identity $VoiceEnabledUser).UserPrincipalName
$MailValue = (Get-ADUser -Identity $VoiceEnabledUser -Properties *).mail
if ($MailValue -ne $null) {
$UMStatus = (Get-Mailbox $UPNUser).UMEnabled
if ($UMStatus -ne "True") {
$SIPAddress = (Get-CsUser -Identity $UPNUser).SipAddress
$SIP = $SIPAddress.Substring(4)
$Line = (Get-CsUser -Identity $UPNUser).LineURI
$Extension = $Line.Substring(($Line.Length)-3)
$Policy = Get-UMMailboxPolicy "SfB Policy"
Enable-UMMailbox -Identity $UPNUser -UMMailboxPolicy $Policy.Name -SIPResourceIdentifier $SIP -Extensions $Extension -PinExpired $true
$UMStatusNew = (Get-Mailbox $UPNUser).UMEnabled
$NormalEmailTemp = @"
<tr>
<td class="colorm">$UPNUser</td>
<td>$UMStatus</td>
<td>$UMStatusNew</td>
</tr>
"@
$NormalEmailResult = $NormalEmailResult + "`r`n" + $NormalEmailTemp
$NormalEmailUp = @"
<style>
body { font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; color:#434242;}
TABLE { font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TR {border-width: 1px;padding: 10px;border-style: solid;border-color: white; }
TD {font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; border-width: 1px;padding: 10px;border-style: solid;border-color: white; background-color:#C3DDDB;}
.colorm {background-color:#58A09E; color:white;}
.colort{background-color:#58A09E; padding:20px; color:white; font-weight:bold;}
.colorn{background-color:transparent;}
</style>
<body>
<h3> Unified Messaging Activation</h3>
<p>Unified Messaging has been activated on the below users:</p>
<table>
<tr>
<td class="colort">User</td>
<td class="colort">UM Old</td>
<td class="colort">UM New</td>
</tr>
"@
$NormalEmailDown = @"
</table>
</body>
"@
$NormalEmail = $NormalEmailUp + $NormalEmailResult + $NormalEmailDown
send-mailmessage `
-To $To `
-Subject "UM Activation Report $(Get-Date -format dd/MM/yyyy)" `
-Body $NormalEmail `
-BodyAsHtml `
-Priority high `
-UseSsl `
-Port 587 `
-SmtpServer 'smtp.office365.com' `
-From $From `
-Credential $EmailCredentials
}
}
}
if ($error -ne $null) {
foreach ($value in $error) {
$ErrorEmailTemp = @"
<tr>
<td class="colorm">$value</td>
</tr>
"@
$ErrorEmailResult = $ErrorEmailResult + "`r`n" + $ErrorEmailTemp
}
$ErrorEmailUp = @"
<style>
body { font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; color:#434242;}
TABLE { font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TR {border-width: 1px;padding: 10px;border-style: solid;border-color: white; }
TD {font-family:Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif !important; border-width: 1px;padding: 10px;border-style: solid;border-color: white; background-color:#C3DDDB;}
.colorm {background-color:#58A09E; color:white;}
.colort{background-color:#58A09E; padding:20px; color:white; font-weight:bold;}
.colorn{background-color:transparent;}
</style>
<body>
<h3 style="color:#BD3337 !important;"> WARNING!!!</h3>
<p>There were errors during actrivation of Unified Messaging</p>
<p>Please check the errors and act accordingly</p>
<table>
"@
$ErrorEmailDown = @"
</table>
</body>
"@
$ErrorEmail = $ErrorEmailUp + $ErrorEmailResult + $ErrorEmailDown
send-mailmessage `
-To $To `
-Subject "UM Activation Error Report $(Get-Date -format dd/MM/yyyy) - WARNING" `
-Body $ErrorEmail `
-BodyAsHtml `
-Priority high `
-UseSsl `
-Port 587 `
-SmtpServer 'smtp.office365.com' `
-From $From `
-Credential $EmailCredentials
}
Leave a Reply