Powershell – How to set msExchMailboxGUID using powershell or any other method

active-directoryexchange-2010powershell

I need to set the msExchMailboxGUID for many accounts in bulk. My input for this data comes from the Powershell command Get-MailboxStatistics. In it is an object that has the GUID for the mailbox.

I need to save that GUID into AD, so this is what I'm doing to GET the object:

   $thisDN = $oneUser.DistinguishedName
   $user = [ADSI]"LDAP://$thisDN"  

  try 
  {
     $user.get("msExchMailboxGUID")
  }
  catch
  {
      $desc = ""
  }

What is the correct way to Set the object?

I'm unable to use "set" or "put" to upload and save the error. It would even be better if someone can point me to detailed object details since I'm not sure where to look for details on something that is instantiated with the [ADSI] brackety thing.

If this is just using the COM ADSI objects, then what is the correct syntax for "put"? I've tried parentheses, commas, and am unable to get Powershell to talk COM.

Best Answer

Continuing from your example, this would work:

$guid = $user.get("msExchMailboxGUID")

$thisDN2 = $twoUser.DistinguishedName
$user2 = [ADSI]"LDAP://$thisDN2"

$user2.put('msExchMailboxGUID', @($guid))
$user2.setinfo()