Powershell-组织者的电子邮件地址

时间:2019-03-13 12:22:27

标签: powershell exchange-server

我正在尝试使用Powershell检索MS Exchange 2010中会议组织者的电子邮件地址。

(Get-Mailbox -Identity "John Doe").PrimarySmtpAddress

我收到以下错误

  

由于在'xxxxxxxxxxxxxx'上找不到对象'John Doe',所以无法执行该操作

这些用于刚刚创建的会议,那么组织者怎么不存在?

编辑:

这是事件的顺序:

  • 在特定日期范围内通过交换获取日历事件列表
  • 获取每个事件的管理器电子邮件地址<-这是我遇到的问题

完整脚本:

$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://xxxxxxxxxxxxxxx/PowerShell -Authentication kerberos -Credential $credential
Import-PSSession -Session $session -DisableNameChecking

#Date ranges
$exportDate = Get-Date -Format d
$startTime = (Get-Date).AddDays(-1) 
$endTime = (Get-Date).AddDays(+1)

$app = New-Object -ComObject Outlook.Application
$ns = $app.GetNamespace('MAPI')
$calFolder = 9
$calItems = $ns.GetDefaultFolder($calFolder).Items
$calItems.Sort("[Start]")
$calItems.IncludeRecurrences = $true
$dateRange = "[Start] >= '{0}' AND [End] <= '{1}'" -f $startTime.ToString("g"), $endTime.ToString("g")
$calExport = $calItems.Restrict($dateRange)

$exportFile = "D:\file.csv"
$calExport | select Subject, StartInStartTimeZone, EndInEndTimeZone, Duration, Organizer, RequiredAttendees, OptionalAttendees, Location | sort StartUTC -Descending | Export-Csv $exportFile
$exportData = Import-Csv $exportFile

foreach ($line in $exportData)
    {
        $emailAddress = $line.Organizer
        $emailAddress = (Get-Mailbox -Identity $line.Organizer).PrimarySmtpAddress
        $line | Add-Member -Membertype Noteproperty -Name OrganizerEmail -Value $emailAddress
        [array]$csvData += $line
        $emailAddress = $null
    }

Remove-PSSession $session

请协助!

1 个答案:

答案 0 :(得分:0)

这是我用来获取组织者电子邮件地址的地址

 Get-ADUser -Filter {SamAccountName -like "*John Doe*"}