[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2750
  • Last Modified:

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.
0
hcca
Asked:
hcca
  • 6
  • 4
1 Solution
 
Justin YeungSenior Systems EngineerCommented:
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
 
hccaAuthor Commented:
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
 
Justin YeungSenior Systems EngineerCommented:
yes of course, however what is your version of exchange?
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
Justin YeungSenior Systems EngineerCommented:
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
 
hccaAuthor Commented:
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
 
Justin YeungSenior Systems EngineerCommented:
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
 
hccaAuthor Commented:
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
 
hccaAuthor Commented:
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
 
hccaAuthor Commented:
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
 
hccaAuthor Commented:
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

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now