user LegacyExchangeDN

administrator 

X500:/o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=2c5af45c0ce4497db28f174659a5e9e1-Admin

<#  
  .概要説明  
   LegacyExchangeDNをADのProxyAddresesに設定します。  
   ドメインコントローラ上でシェルを実行します。ユーザプロパティのプロキシアドレスにレコードを削除します。
  .サンプル  
   Add-UserProxyAddress -CSVFile c:\Script\Delete-LegacyExchangeDN.ps1
     
   CSVファイルから入力を受け取り、それぞれのユーザプロキシアドレス属性にX500:<LegacyExchangeDN>値を削除します。
  .サンプル
   CSV ファイルのデータフォーマット(LegacyExchangeDNの値をダブルクォーテーションで文字列を選択する。)
   ----------------------------------------------
   | user      | LegacyExchangeDN               |
   | --------------------------------------------
   | administrator  | {"X500:/o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recip...}  "|
   | yamada         | {"X500:/o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recip... }"|
   ----------------------------------------------
  .OutPuts  
   username ProxyAddresses
   -------- --------------
   
    
  #>  
   
[CmdletBinding()]
param(  
    [Parameter(Mandatory=$true,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]
    [alias('FilePath','File','CSV','CSVPath')]
    [String]$Path,
    [String]$Protocol='X500') #param
Begin {  
    Import-Module ActiveDirectory
} #Begin

Process {
    $users = Import-Csv -Path $Path
    $temp = [System.IO.Path]::GetTempFileName()
    Foreach ($u in $users) {
        
        Try {
            $user = Get-ADUser -Identity $u.user -ErrorAction Stop
            Write-Host "$($user.SamAccountName) exists, Processing it..." -BackgroundColor DarkGray -NoNewline 
            $LegacyExchangeDN = "{1}:{0}" -f $u.LegacyExchangeDN, $Protocol
            Set-ADUser -Identity $u.user -remove @{Proxyaddresses=$u.LegacyExchangeDN} 
            Write-Host "...ProxyAddress deleted" -BackgroundColor DarkGreen
        }
        catch {
            Write-Host "$($user.SamAccountName) does not exists" -BackgroundColor DarkRed
        }
    } 
    
    $users | foreach {
        $user = $_.user
        Try {
            Set-ADUser -Identity $_.user -Properties ProxyAddresses -ErrorAction Stop | select SamAccountName, Name, ProxyAddresses
        }
        catch {
            Write-Host "$user does not exists" -BackgroundColor DarkRed
        }
    } | Out-File $temp
}
end {
    Notepad $temp
}