Link to home
Start Free TrialLog in
Avatar of hcca
hcca

asked on

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

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.
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

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"}}
Avatar of hcca
hcca

ASKER

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
yes of course, however what is your version of exchange?
ASKER CERTIFIED SOLUTION
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hcca

ASKER

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.
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?
Avatar of hcca

ASKER

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.
Avatar of hcca

ASKER

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.
Avatar of hcca

ASKER

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.
Avatar of hcca

ASKER

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.