I recently wrote a Unified Messaging Provisioning Script and am providing it in two flavors; a simple version of it and the complex version of it.
Simple Script Features (CSV Download)
- $DefaultPIN is exactly that. The CSV has a PIN column which is empty by default. If this CSV field is left blank for a given user, it will use the $DefaultPIN. Otherwise, it will use the PIN specified in the script.
- The Script will search for non-legacy Mailboxes (non-Exchange 2000/2003 Mailboxes if running Exchange 2007) and use the First and Last column (for the user’s first name and last name) in Excel. Because Firstname and Lastname is not unique in AD, the script will error on a user if they have multiple mailboxes. It will tell you to enter the user’s Alias in that user’s Alias column in Excel. The script will then get the mailbox that has that Alias. This doesn’t just rely on Get-Mailbox -identity alias because that can still return multiple mailboxes. It does a Get-Mailbox -identity alias but also does a Where-Object {$_.alias -eq $Mailbox.Alias} to ensure we use the correct mailbox.
- The script will enable the user’s UM Mailbox based on the Mailbox GUID on the mailbox that is retrieved to ensure enable the correct Mailbox based on the unique (GUID) identifier.
- Allows you to set the personal operator extension of a user based on the information in the CSV. If you don’t need to set the Operator Extension, just go into the script and remove the Set-UMMailbox line as everything else is contained in the Enable-UMMailbox line.
- The script assumes you have one UM Mailbox Policy and uses that to assign users to.
Complex Script Features (CSV Download)
- Includes all the features of the Simple Script plus the following:
- Doesn’t send the default SMTP Message to user’s when they are UM Enabled. The variable $NotifyEmail is where you want the welcome message sent which should obviously be a mailbox you perhaps create for the purpose of sending welcome messages to.
- Instead of sending the welcome message to the user’s mailbox when they are UM Enabled, the variable $smtpFrom is where you want a custom html formatted welcome message sent from. This could be something such as [email protected].
- To tweak the custom HTML Formatted message, go down to the variable $EmailBody and include your own HTML. By default, it will sent the user their PIN (if $DefaultPIN is used, that is sent to the user and if there’s a PIN for that user in the CSV, it uses that instead), their Extension, and their Subscriber Access Number as defined in the CSV.
- The script will allow you to choose from two separate UM Mailbox Policies. By default, the script uses North America and London. If you have different UM Mailbox Policies which you most likely will, you will need to go down to the Enable-UMMailbox command to tweak the name of the Policies that are used. If you want to add more, you will need to modify the Write-Host lines near the beginning of the script which gives the user the option what to select and then go down to the Enable-UMMailbox and tweak the elseif pieces to take into consideration the additional UM Mailbox Policies to consider.
Note: The CSV file used for the Complex Script is available for download from here. The one difference between this and the simple version of the CSV is this CSV contains a SubscriberAccess column which the HTML message captures and uses as a variable to send to the user’s primary SMTP address when enabl
Simple Script
###############################
# UM Simple Automation v1
# By Elan Shudnow
###############################
########## MODIFIABLE OPTIONS ##########
# Set This PIN to the Default PIN. If the CSV PIN Field is blank, it uses this. If not blank, it uses the CSV PIN.
$DefaultPIN = 12345
# Set this to the location of the CSV file.
$mailboxes = Import-CSV "UMsimple.csv"
########## DO NOT MODIFY ANYTHING BELOW THIS LINE ##########
# Call the Loop to Enable Users
Foreach ($mailbox in $mailboxes) {
# By default, Excel will have empty Alias Column so it will search by First Last.
if (!($mailbox.alias)) {
$User = Get-Mailbox -Identity ($Mailbox.First + "" + " " + $Mailbox.Last) -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" }
}
else {
$User = Get-Mailbox -Identity $Mailbox.Alias -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.alias -eq $Mailbox.Alias }
}
# By default, Excel will have empty Alias Column so it will search by First Last.
# This will notify you to modify the Alias Column so that you can search on a unique field if there are multiple
# mailboxes with the same First Lastname that are on Exchange 2007. The script ignores Exchange Legacy Mailboxes (Exchange 2000 and Exchange 2003).
if ($User) {
if ($User.Count -gt 1) {
Write-Warning $User "There are multiple users with this First Name and Last Name. Go into the spreadsheet and provide the alias for the correct mailbox user"
}
else {
if ($User.UMEnabled -eq $false) {
Enable-UMMailbox -Identity $User.GUID.toString() -ummailboxpolicy $((Get-UMMailboxPolicy).Identity) -pin $(if (!($mailbox.pin)) { $DefaultPIN } else { $Mailbox.PIN }) -pinexpired $true -Extensions $Mailbox.Extension -NotifyEmail $NotifyEmail
Set-UMMailbox -Identity $User.GUID.toString() -OperatorNumber $Mailbox.Operator
}
else {
Write-Host $User "is already enabled"
}
}
}
else {
Write-Host "ERROR:" ($Mailbox.First + "" + " " + $Mailbox.Last) "'s Mailbox Does Not Exist"
}
}
Complex Script
###############################
# UM Complex Automation v1
# By Elan Shudnow
###############################
########## MODIFIABLE OPTIONS ##########
# Set This PIN to the Default PIN. If the CSV PIN Field is blank, it uses this. If not blank, it uses the CSV PIN.
$DefaultPIN = 12345
# Set this to the location of the CSV file.
$mailboxes = Import-CSV "UMcomplex.csv"
# Set this to the Notify Email you want.
$NotifyEmail = "[email protected]"
# Set this to the e-mail address where users will receive Welcome Messages From
$smtpFrom = “[email protected]"
$smtpServer = "hubserver.domain.com"
########## DO NOT MODIFY ANYTHING BELOW THIS LINE ##########
# Allows the user running the script to choose which UM Mailbox Policy the group of users in the CSV
# should belong to. This will assign the policy to all users in the given CSV file.
write-host
write-host Exchange Server 2010 - Unified Messaging Enabling
write-host Please, select which UM Mailbox Policy you want assigned
write-host
write-host '1) North America'
write-host '2) London'
write-host
$location = Read-Host "Select an option.. [1-2]? "
function Send-Email {
Param ($To, $From, $Subject, $Body)
$msg = New-Object Net.Mail.MailMessage
$msg.From = $From
$msg.To.Add($To)
$msg.IsBodyHtml = $true
$msg.Body = $Body
$msg.Subject = $Subject
$client = New-Object net.Mail.SmtpClient($smtpServer)
$client.Send($msg)
}
# Call the Loop to Enable Users
Foreach ($mailbox in $mailboxes) {
# By default, Excel will have empty Alias Column so it will search by First Last.
if (!($mailbox.alias)) {
$User = Get-Mailbox -Identity ($Mailbox.First + "" + " " + $Mailbox.Last) -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" }
}
else {
$User = Get-Mailbox -Identity $Mailbox.Alias -ResultSize Unlimited -ErrorAction SilentlyContinue | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.alias -eq $Mailbox.Alias }
}
# By default, Excel will have empty Alias Column so it will search by First Last.
# This will notify you to modify the Alias Column so that you can search on a unique field if there are multiple
# mailboxes with the same First Lastname that are on Exchange 2007. The script ignores Exchange Legacy Mailboxes (Exchange 2000 and Exchange 2003).
if ($User) {
if ($User.Count -gt 1) {
Write-Warning $User "There are multiple users with this First Name and Last Name. Go into the spreadsheet and provide the alias for the correct mailbox user"
}
else {
if ($User.UMEnabled -eq $false) {
Enable-UMMailbox -Identity $User.GUID.toString() -ummailboxpolicy $(if ($location -eq 1) { "North America" } else { "London" }) -pin $(if (!($mailbox.pin)) { $DefaultPIN } else { $Mailbox.PIN }) -pinexpired $true -Extensions $Mailbox.Extension -NotifyEmail $NotifyEmail
Set-UMMailbox -Identity $User.GUID.toString() -OperatorNumber $Mailbox.Operator
$Extension = $Mailbox.Extension
$Pin = $(if (!($mailbox.pin)) { $DefaultPIN } else { $Mailbox.PIN })
$SubscriberNumber = $Mailbox.SubscriberNumber
$EmailBody = @"
Welcome to Exchange Unified Messaging!
Your Extension is $Extension
Your PIN is $Pin
Your Subcriber Access Number is $SubscriberNumber
"@
$EmailSub = “Welcome to Exchange Unified Messaging!”
$EmailTo = $User.PrimarySmtpAddress
$EmailFrom = $smtpFrom
Send-Email $EmailTo $EmailFrom $EmailSub $EmailBody
}
else {
Write-Host $User "is already enabled"
}
}
}
else {
Write-Host "ERROR:" ($Mailbox.First + "" + " " + $Mailbox.Last) "'s Mailbox Does Not Exist"
}
}
Shri says
Hi there,
I am a new beginner to exchange and wondering where and how can I get the CSV list and What fields should it contain?
Can I export it from Exchange?
Please advise
S
ameya says
Does this script also apply to Exchange 2013 Unified Messaging. I tried to use the script, UM is getting enabled for the user but I also get below error
Cannot convert argument "item", with value: "<email id>l", for "Add" to type
"System.Net.Mail.MailAddress": "Cannot convert the "<mail id>" value of type
"Microsoft.Exchange.Data.SmtpAddress" to type "System.Net.Mail.MailAddress"."
At E:""PSScript-EnableUMv0.1.ps1:40 char:2
+ $msg.To.Add($To)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
Exception calling "Send" with "1" argument(s): "A recipient must be specified."
At E:""PSScript-EnableUMv0.1.ps1:47 char:5
+ $client.Send($msg)
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
Rami Ahmad says
what is the "operator" mentioned in the CSV file? what I have to include in this field
Eugene says
How can I let the exchange use the default voice mail extension instead of from the CSV? All my users have a business phone as their mailbox extension.
Elan Shudnow says
Remove -Extensions $Mailbox.Extension from the script. By leaving -Extensions out, a system assigned extension will be used.
Andrew Parisio says
Hi, I used a slightly modified version of your simple tool and would like to say thanks, and let you know about what I did. I included it in my blog post here:
http://www.andrewparisio.com/2011/02/asterisk-wit…
Thank you!