Powershell:从O365拉取时LegacyExchangeDN值被截断

Powershell:从O365拉取时LegacyExchangeDN值被截断,powershell,csv,Powershell,Csv,通过PowerShell,我登录到O365并运行以下程序,将数据提取并输出到CSV文件: function O365Logon { #Check for current open O365 sessions and allow the admin to either use the existing session or create a new one $session = Get-PSSession | ?{$_.ConfigurationName -eq 'Microsoft.Exchan

通过PowerShell,我登录到O365并运行以下程序,将数据提取并输出到CSV文件:

function O365Logon
{
#Check for current open O365 sessions and allow the admin to either use the existing session or create a new one
$session = Get-PSSession | ?{$_.ConfigurationName -eq 'Microsoft.Exchange'}
if($session -ne $null)
{
    $a = Read-Host "An open session to Office 365 already exists.  Do you want to use this session?  Enter y to use the open session, anything else to close and open a fresh session."
    if($a.ToLower() -eq 'y')
    {
        Write-Host "Using existing Office 365 Powershell Session." -ForeGroundColor Green
        return  
    }
    $session | Remove-PSSession
}
Write-Host "Please enter your Office 365 credentials" -ForeGroundColor Green
$cred = Get-Credential
$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
$importresults = Import-PSSession -Prefix "Cloud" $s
}

function Main
{

#Import user list from migration.csv file. Specifies account names to retrieve data for
$MigrationCSV = Import-Csv $migrationCSVFileName

#Get mailbox list based on email addresses from CSV file
$MailBoxList = $MigrationCSV | %{$_.EmailAddress} | Get-CloudMailbox
$Users = @()

#Get LegacyDN, Tenant, On-Premise Email addresse, and MailBox GUID for each of the users
$Outfile = ".\cloud.csv"
'LegacyExchangeDN,CloudEmailAddress,OnPremiseEmailAddress,MailboxGUID' | Set-Content $Outfile


foreach($user in $MailBoxList)
{
$CloudEmailAddress = $user.EmailAddresses | ?{($_ -match 'onmicrosoft') -and ($_ -cmatch 'smtp:')}

    if ($CloudEmailAddress.Count -gt 1)
    {
        $CloudEmailAddress = $CloudEmailAddress[0].ToString().ToLower().Replace('smtp:', '')
        Write-Host "$user returned more than one cloud email address.  Using $CloudEmailAddress" -ForegroundColor Yellow
    }
    else
    {
        $CloudEmailAddress = $CloudEmailAddress.ToString().ToLower().Replace('smtp:', '')
    }

  $Data = @(
             $user.LegacyExchangeDN,
             $CloudEmailAddress,
             $user.PrimarySMTPAddress.ToString(),
             $user.ExchangeGUID 
            )
 '"{0}",{1},{2},{3}' -f $Data | Add-Content $Outfile
}


Write-Host "File Successfully Exported to cloud.csv" -ForeGroundColor Green

}
问题是,在控制台输出和CSV文件中,第一个$user.LegacyExchangeDN值始终被截断为128个字符

返回的数据示例:

/o=ExchangeLabs/ou=Exchange管理组FYDIBOHF23SPDLT/cn=Recipients/cn=a0dd27b566c841108cfa61a3494206c6乔纳森,M,mJonathan@ThisSampleDomainGroup.onmicrosoft.com,mJonathan@ThisSampleDomain.com,49C38C07-6997-4D4D-9449-EBD5A53E3D02

/o=ExchangeLabs/ou=Exchange管理组FYDIBOHF23SPDLT/cn=Recipients/cn=ba1189838c964929bff706a23900d41c Chri史密斯,cSmith@ThisSampleDomainGroup.onmicrosoft.com,cSmith@ThisSampleDomain.com,9F0E3433-6749-47B7-96E5-987CF5ACF60D

您将看到每个用户的名字都被截断,但不同

我最初以为这些名字在O365中被截断了,但有人告诉我这不是真的。关于如何排除故障或解决问题,您有什么想法吗?

似乎没有提到Get CloudMailbox。您使用的是连接MsolService还是PowerShell连接到

您是否尝试过使用Get邮箱

Get-Mailbox -Identity mJonathan@ThisSampleDomain.com | Select LegacyExchangeDN | FL
编辑:

编辑2:


我正在使用Get-PSSession连接到Microsoft。Exchange我已添加用于连接的O365功能。我尝试使用Get-Mailbox命令,但无法识别。它很好地导入了其他命令,但不知道oneget邮箱是通过控制台工作的,而不是通过PowerGui工作的。忽略运行get-mailbox命令的问题。好的,我得到了get-mailbox命令的结果,它是相同的截断字符串。
Get-CloudMailbox -Identity mJonathan@ThisSampleDomain.com | Select-Object -ExpandProperty LegacyExchangeDN
(Get-CloudMailbox -Identity mJonathan@ThisSampleDomain.com | Select LegacyExchangeDN -ExpandProperty LegacyExchangeDN).Length