Solved

Use Powershell to find msExchVersion with null value and then replace it

Posted on 2014-07-22
10
2,111 Views
Last Modified: 2014-07-23
I have a number of accounts that have been created in Exchange 2010 from a script that end up as Legacy Mailboxes. I've seen several sources with scripts to fix this but they do not work. The issue is that the value of the AD Attribute msExchVersion is null. I need to find the mailboxes in a specific OU that have this null value and then set the msExchVersion to 44220983382016 for Exchange 2010. Using the AD tools I can find the null values with this:
Get-ADUser -LDAPFilter "(!(msExchVersion=*))" -resultSetSize $null -searchbase "OU=Test,OU=TestUsers,OU=VOIP,OU=User Accounts,DC=dp,aom,DC=priv" 

Open in new window

However, I cannot find a way to set the attribute to the correct value.

I'm happy to use the AD commands or the quest commands so long as it works. Your assistance is appreciated.
0
Comment
Question by:hcca
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212477
Get-ADUser -LDAPFilter "(!(msExchVersion=*))" -resultSetSize $null -searchbase "OU=Test,OU=TestUsers,OU=VOIP,OU=User Accounts,DC=dp,aom,DC=priv"  | % {set-aduser $_ -add @{msExchVersion="44220983382016"}}
0
 

Author Comment

by:hcca
ID: 40212530
That works very well. Is there any way to add something like this to the script? This uses Exchange commands instead of AD commands. I left out the part where I set the  variable $dn hoping that I could use what was returned from the first part of the script.

Get-User "$dn" -IgnoreDefaultScope | Update-Recipient
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212555
yes of course, however what is your version of exchange?
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 40212575
Import-Module ActiveDirectory
Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010

$Users = Get-ADUser -LDAPFilter "(!(msExchVersion=*))" -resultSetSize $null -searchbase "OU=Test,OU=TestUsers,OU=VOIP,OU=User Accounts,DC=dp,aom,DC=priv"  
foreach ($User in $Users)
{
Set-aduser $User.SamAccountName -add @{msExchVersion="44220983382016"}
Start-sleep -second 2
Get-Mailbox $User.DistinguishedName -IgnoreDefaultScope | Update-Recipient
} 

Open in new window

0
 

Author Comment

by:hcca
ID: 40212624
The second part of this worked perfectly but it failed to set the Exchange version.

I had run the earlier script which did set the version. I then reset the version to <not set> for one user. When I ran the latest version I expected that to be corrected as well as the second part. I got this error in the PS window.

WARNING: The object domain.priv/User Accounts/VOIP/TestUsers/TEST/End User has been corrupted, and it's in an
inconsistent state. The following validation errors happened:
WARNING: ExchangeGuid is mandatory on UserMailbox.
WARNING: ExchangeGuid is mandatory on UserMailbox.
Property RoleAssignmentPolicy can't be set on this object because it requires the object to have version 0.10 (14.0.100
.0) or later. The object's current version is 0.0 (6.5.6500.0).
    + CategoryInfo          : NotSpecified: (0:Int32) [Update-Recipient], InvalidObjectOperationException
    + FullyQualifiedErrorId : 650032ED,Microsoft.Exchange.Management.RecipientTasks.UpdateRecipient

The problem did not occur for the users that I did not remove the msExchVersion value. Those accounts are now ready to go.
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40212723
so the user was in Exchange 2003? didn't you already migrated the mailbox over to 2k10?

why don't you change the attribute back to what it was and let exchange to handle the update?
0
 

Author Comment

by:hcca
ID: 40212773
I think this may be working fine. I've had a couple of squirrely things happen. I will get another batch to test with tomorrow. Thanks for your fine help. I was close with a couple of my attempts but you, Justin Yeung, nailed it all down.
0
 

Author Closing Comment

by:hcca
ID: 40212788
These accounts are being created through an AD sync process using FIM2010 with a vbproject. For some reason, when it creates the account it does not populate it completely for a regular exchange mailbox. I've seen a couple of posts that suggest running this:
Get-Mailbox | where {$_.RecipientTypeDetails -eq "legacymailbox"} | Set-Mailbox -ApplyMandatoryProperties
But that does not fix this issue. However, adding the msExchVersion by hand and then running -IgnoreDefaultScope | Update-Recipient against the boxes converts them to regular mailboxes and it all works. I know the real fix is to get the FIM2010 script to run properly. That will be my next step, but I needed a quick fix for a bunch of accounts coming down the pipe.
0
 

Author Comment

by:hcca
ID: 40215067
Last comment. I found that by adjusting the wait time from 2 to 10 fixed my problem. It takes a bit longer to complete but it does complete. The script will never be used for more than 12-20 accounts at a time.

Thanks for all the help.
0
 

Author Comment

by:hcca
ID: 40215393
Justin Yeung thanks for your help. I have found that if the script finds zero users with a null value for msExchVersion it continues on to the next part of the script. Is it possible to have the script end if no users are found with the null value? I've tried inserting some if / else code but have not been successful.
0

Join & Write a Comment

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now