locked
Simple powershell one liner to change legacyExchangeDN? RRS feed

  • Question

  • Can anyone share a simple clean short, to the point, one line powershell that changes the legacyExchangeDN value on one mailbox?
    Thursday, October 18, 2012 4:28 PM

Answers

  • I was forced to use ADSI Edit when I could not change it through power shell.
    Wednesday, October 24, 2012 5:32 PM

All replies

  • Well, I would want to know why you want to change it first :)

    That is typically not a good idea. Better to add the legacyExchangeDN as an additional Custom X500 address to the account instead.

    Thursday, October 18, 2012 5:17 PM
  • Well, I would want to know why you want to change it first :)

    That is typically not a good idea. Better to add the legacyExchangeDN as an additional Custom X500 address to the account instead.

    The account needs the legacyExchangeDN attribute corrected from being established wrong then changed through the ADUC ui.

    I want to know how to edit the value via a short powershell command. I found how to list it, I just can't set it.

    Is there a small clean example of powershell to set it on one user?

    Thursday, October 18, 2012 5:22 PM
  • I would look at this perhaps

    Note that changing this will affect cached entries and replies from Outlook users.

    Thursday, October 18, 2012 5:28 PM
  • I would look at this perhaps

    Note that changing this will affect cached entries and replies from Outlook users.

    Thanks, unfortunately I found that example already. It's not what I'd consider a simple one liner though. I don't write code and I don't have time in a day to craft powershell scripts.  Is there maybe another simpler one? Anyone?

    Thursday, October 18, 2012 5:41 PM
  • Does it really need to be done in Powershell? I would just change it using adsiedit.msc
    Thursday, October 18, 2012 5:48 PM
  • I would not change the legacyExchangeDN for the issues Andy cited, I would add the old legacyExchangeDN to the proxy addresses as a custom entry though, it will have practically the same effect aside from the nasty missing cache entry issue.

    Set-Mailbox <user> -EmailAddresses @{add="X500:/o=<ExOrg>/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Userabc"}

    If you really must change it, you can flip flop them by using:

    import-module ActiveDirectory
    $user=<username>
    $NewExDN=<NewLegacyExchangeDN>
    $OldExDN = $(Get-Mailbox $user).LegacyExchangeDN
    Set-Mailbox $user -EmailAddresses @{Add="X500:$OldExDN"}
    Set-ADUser $user -Replace @{legacyExchangeDN=$NewExDN}

    Just put the username in and the the legacyExchangeDN you want, and the script will move the existing legacyExchangeDN to the proxyAddresses and change the existing legacyExchangeDN attribute.

    *** Use at your own risk, unforseen issues can come from changing this attribute ***


    • Edited by Russ Burden Thursday, October 18, 2012 7:07 PM
    Thursday, October 18, 2012 6:54 PM
  • So then, it cannot be done via powershell in a simple manner. That's what I'm taking away from this thread and all the dead end threads out there.

    OK.

    Thursday, October 18, 2012 7:03 PM
  • So then, it cannot be done via powershell in a simple manner. That's what I'm taking away from this thread and all the dead end threads out there.

    OK.

    The LegacyExchangeDN is one of those special attributes that should rarely be missed with, so that is most likely why you dont see any built-in tools to manipulate it.

    Thursday, October 18, 2012 7:05 PM
  • On Thu, 18 Oct 2012 17:28:44 +0000, Andy D- wrote:
     
    >I would look at this perhaps
    >
    >Note that changing this will affect cached entries and replies from Outlook users.
     
    .... and ownership of items in calendars, especially any "shared"
    calendars.
     
    Changing the LDN isn't a good idea.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, October 18, 2012 9:24 PM
  • If you need to change the legacyExchangedn for users, you can use ADmodify to help you do that.

    Introduction to ADModify.net

    http://technet.microsoft.com/en-us/library/aa996216(EXCHG.65).aspx

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tnmff@microsoft.com


    Evan Liu

    TechNet Community Support

    Friday, October 19, 2012 8:29 AM
    Moderator
  • How about the issue, any updates?

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tnmff@microsoft.com


    Evan Liu

    TechNet Community Support

    Wednesday, October 24, 2012 10:15 AM
    Moderator
  • I was forced to use ADSI Edit when I could not change it through power shell.
    Wednesday, October 24, 2012 5:32 PM
  • #############################################################################################################################################################################
    # VISUALIZAR O ATRIBUTO "LegacyExchangeDN" (VIEW ATTRIBUTE)
    #Get-QADUser u10000 -Properties * | fl *legacyExchangeDN*
    #
    # ALTERAR O ATRIBUTO "LegacyExchangeDN" (CHANGE ATTRIBUTE)
    #Get-QADUser u10000 -Properties * | Set-QADUser -objectattributes @{legacyExchangeDN="/o=CONTOSO/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=u10000"
    ##############################################################################################################################################################################

    # IMPORTAR RESULTADO DA CONSULTA PARA DENTRO DA VARIAVEL $LegacyExchOld

    # IMPORT RESULTS OF CONSULTATIONS WITH INSIDE THE VARIABLE $LegacyExchOld

    $LegacyExchOld = (Get-QADUser -SizeLimit "0" -Properties "*"| Select -Property SamAccountName,DisplayName,legacyExchangeDN,DN)

    # IMPORTA SOMENTE O RESULTADO DA CONSULTA QUE POSSUIR O CAMPO "DESIS"

    # CARE ONLY RESULT OF CONSULTATION TO HAVE THE FIELD "DESIS"

    $SelectOldLegacyExch = $LegacyExchOld | ? {($_.legacyExchangeDN -like "*DESIS*")} | select SamAccountName,legacyExchangeDN

    # SUBSTITUIR APENAS O NOME "DESIS" POR "Exchange Administrative Group (FYDIBOHF23SPDLT)"

    # REPLACE ONLY THE NAME "DESIS" TO "Exchange Administrative Group (FYDIBOHF23SPDLT)"

    $ReplaceNewLegacyExch = $SelectOldLegacyExch |% {$_.legacyExchangeDN -Replace "DESIS", "Exchange Administrative Group (FYDIBOHF23SPDLT)"}

    # ALTERAR "legacyExchangeDN"

    # CHANGE "legacyExchangeDN"

    $SelectOldLegacyExch |% {Get-QADUser $_.SamAccountName | Set-QADUser -objectattributes @{legacyExchangeDN=($_.legacyExchangeDN -Replace "DESIS", "Exchange Administrative Group (FYDIBOHF23SPDLT)")}}

    # CONFERIR MUDANÇAS.

    # VALIDATE CHANGES.

    Get-QADUser -SizeLimit "0" -Properties "*"| Select -Property SamAccountName,legacyExchangeDN

    ##############################################################################################################################################################################
    # PENSAMENTO 1 (Ideia) | *THOUGHT 1* ONLY 1 USER
    #set-qaduser USERNAME -objectattributes @{legacyExchangeDN="DN_OF_EXCHANGE"}
    #
    # PENSAMENTO 2 (Funciona Apenas para Um usuário) | *THOUGHT 2* ONLY 1 USER
    $SelectOldLegacyExch |% {Set-QADUser $_.SamAccountName -objectattributes @{legacyExchangeDN=$ReplaceNewLegacyExch}}
    #
    # PENSAMENTO 3 (Funciona para uma Lista de Usuários) | *THOUGHT 3* LIST USERS
    #$SelectOldLegacyExch |% {Get-QADUser $_.SamAccountName | Set-QADUser -objectattributes @{legacyExchangeDN=($_.legacyExchangeDN -Replace "DESIS", "Exchange Administrative Group (FYDIBOHF23SPDLT)")}}
    ##############################################################################################################################################################################

    Eu fiz assim e deu certinho..

    Language = PTBR

    Gláucia Diniz..

    MCSE 2013



    • Edited by Gláucia_pop Wednesday, February 11, 2015 2:12 PM
    Wednesday, February 11, 2015 2:01 PM