Powershell:从O365拉出时,LegacyExchangeDN值会被截断

时间:2014-04-17 16:08:07

标签: 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.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

}

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

示例返回数据:

" / o = ExchangeLabs / ou = Exchange管理组(FYDIBOHF23SPDLT)/ cn =收件人/ cn = a0dd27b566c841108cfa61a3494206c6- Jonathan,M ",mJonathan @ ThisSampleDomainGroup.onmicrosoft。玉米,mJonathan @ ThisSampleDomain.com,49C38C07-6997-4D4D-9449-EBD5A53E3D02

" / o = ExchangeLabs / ou = Exchange管理组(FYDIBOHF23SPDLT)/ cn =收件人/ cn = ba1189838c964929bff706a23900d41c- Smith,Chri ",cSmith @ ThisSampleDomainGroup.onmicrosoft。 COM,输入csmith @ ThisSampleDomain.com,9F0E3433-6749-47B7-96E5-987CF5ACF60D

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

我首先想到的是O365中的名字被截断,但被告知这不是真的。有关如何排除故障或解决的任何想法?

1 个答案:

答案 0 :(得分:0)

http://help.outlook.com/140/dd575549.aspx#Mailboxes似乎没有引用Get-CloudMailbox。您是使用Connect-MsolService还是与https://ps.outlook.com/powershell/建立的PowerShell连接?

您是否尝试过使用Get-Mailbox?

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

修改

Get-CloudMailbox -Identity mJonathan@ThisSampleDomain.com | Select-Object -ExpandProperty LegacyExchangeDN

编辑#2:

(Get-CloudMailbox -Identity mJonathan@ThisSampleDomain.com | Select LegacyExchangeDN -ExpandProperty LegacyExchangeDN).Length