Script problem with set-mailbox

  • Thread starter mjolinor
  • Start date Views 1,128
M

mjolinor



I'm trying to set up some maintenance scripts for phone number maintenance. When users move, they can't always take their phone number with them, so we have to update their phone number in AD, and frequently their UM extension to match. The following script is a test version of what I'm trying to get to work in production.

The phone number field gets updated fine.

The set-mailbox cmdlet doesn't want to update the EUM address. If I output the proxy address strings everything looks right, and I don't get any errors on operation, but the EUM address just never gets updated in the directory.

Can anyone tell my why this is not working, or what I need to do different?

$user = ""|select display_name,phone,pri_um,sec_um,UM_enabled

$user.display_name = "<user name>"

$user.phone = (get-user $user.display_name).phone
$user.um_enabled = "true"

$mbx = get-mailbox $user.display_name
$um_addrs = @($mbx.emailaddresses |?{$_ -match "eum:"})
$sec_addrs = @()
$um_addrs |% {
if ($_ -cmatch "EUM:(\d+);"){$user.pri_um = $matches[1]}
elseif ($_ -cmatch "EUM:\w+@\w+"){$user.pri_um = "OCS"}
else {$sec_addrs += $matches[1]}
}
$user.sec_um = [string]$sec_addrs
$user

$newphone = $null
while ($newphone -notmatch "\d\d\d\d"){
$newphone = read-host "Enter new phone number (4 digit)"
}
if ($user.um_enabled -eq "True" -and $user.pri_um -match "\d\d\d\d"){
while ($verify -notmatch "y|n"){
$verify = Read-Host "User is UM enabled. Update Primary UM to match new phone number? (y\n)"
}
if ($verify -eq "y"){
$mbx.emailaddresses |% {Write-Host "$($_.proxyaddressstring)"}
$oldum = ($mbx.emailaddresses |? {$_.proxyaddressstring -clike "EUM*"}).proxyaddressstring
$mbx.emailaddresses -= $oldum
$mbx.EmailAddresses += "EUM:" + $newphone + ";phone-context=Mitel.CBC.CTS"
$mbx.EmailAddresses |% {Write-Host "$($_.proxyaddressstring)"}
$mbx | set-mailbox
}
Set-User $user.display_name -Phone $newphone
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
 
M

mjolinor



Tried anohter tack, and still no luck:

Using this script:

$user = ""|select display_name,phone,pri_um,UM_enabled,sec_um

$user.display_name = "tbrian tbackestest"

$user.phone = (get-user $user.display_name).phone
$user.um_enabled = "true"

$mbx = get-mailbox $user.display_name
$um_addrs = @($mbx.emailaddresses |?{$_ -match "eum:"})
$sec_addrs = @()
$um_addrs |% {
if ($_ -cmatch "EUM:(\d+);"){$user.pri_um = $matches[1]}
elseif ($_ -cmatch "EUM:\w+@\w+"){$user.pri_um = "OCS"}
else {$sec_addrs += $matches[1]}
}
$user.sec_um = [string]$sec_addrs
$user

$newphone = $null
while ($newphone -notmatch "\d\d\d\d"){
$newphone = read-host "Enter new phone number"
}
Set-User $user.display_name -Phone $newphone
if ($user.um_enabled -eq "True" -and $user.pri_um -match "\d\d\d\d"){
while ($verify -notmatch "y|n"){
$verify = Read-Host "User is UM enabled. Update Primary UM to match new phone number? (y\n)"
}


if ($verify -eq "y"){
$mbx = Get-Mailbox $user.display_name
for ($i=0; $i -lt $mbx.emailaddresses.count; $i++){

if ($mbx.emailaddresses.item($i).proxyaddressstring -clike "*EUM:*"){
$mbx.emailaddresses.item($i) = "EUM:" + $newphone + ";phone-context=Mitel.CBC.CTS"
}
}
}
$mbx.EmailAddresses |% {Write-Host "$($_.proxyaddressstring)"}
$mbx | set-mailbox
}


I get this result:

[PS] C:\scripts\um>./maint2.ps1
display_name : tbrian tbackestest
phone : 7799
pri_um : 6461
UM_enabled : true
sec_um :

Enter new phone number: 7798
User is UM enabled. Update Primary UM to match new phone number? (y\n): y
EUM:7798;phone-context=Mitel.CBC.CTS
SIP:TBrian_TBackesTest@domain.com
X400:C=US;A= ;P=CBC;O=006OPERATIONS;S=BackesTest;G=Brian;
smtp:Brian_BackesTest@domain.net
SMTP:Brian_BackesTest@domain2.com
WARNING: The command completed successfully but no settings of 'CBC.CTS/Test Accounts/TBrian TBackesTest' have
been modified.
[PS] C:\scripts\um>

According to this:

http://technet.microsoft.com/en-us/library/bb232208.aspx

and this:

http://technet.microsoft.com/en-us/library/dd335124.aspx

http://technet.microsoft.com/en-us/library/dd351124.aspx

These scripts should be working, but they will not update the UM extension for the user.

The only thing that does work is to UM-disable the user, and then re-enable them with a new number. Enabling and disabling UM users only seems to work from within the EMS shell. Just loading the Exchange modules into Powershell (e.g. from the PowerShell Modules Admin console) doesn't work. All the other Exchange cmdlets seem to work in that console, except for enable-ummailbox and disable-ummailbox. With those you get this:

PS C:\> disable-ummailbox tbrian_tbackestest
Disable-UMMailbox : The process failed to read the Exchange topology in the allotted time.
At line:1 char:18
+ disable-ummailbox <<<< tbrian_tbackestest
+ CategoryInfo : NotSpecified: (0:Int32) [Disable-UMMailbox], ReadTopologyTimeoutException
+ FullyQualifiedErrorId : 8A49702,Microsoft.Exchange.Management.Tasks.UM.DisableUMMailbox

PS C:\>

This is getting very frustrating............

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
 
J

jader3rd



I think the problem is
$mbx | set-mailbox

I'm pretty sure under the Exchange 2010 RBAC'd remote PowerShell, that this line is a no op. Instead of building up an object and then passing it to a set cmdlet (which works for all other PowerShell), it doesn't work in Exchange 2010.
 
M

mjolinor

There are -secondaryaddress and -secondarydialplan parameters for set-mailbox that seem to be for adding (one) secondary um extension. There doesn't seem to be a parameter to set the primary UM address, or deal with more than one secondary UM extension.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
 

Top