简体   繁体   English

导出所有公用文件夹的电子邮件地址

[英]Export e-mail address for all public folders

I have a large group of public folders.我有一大群公用文件夹。 Each folder has a minimum of 3 up to a max of 20 e-mails address that will direct to that public folder.每个文件夹至少有 3 个,最多 20 个电子邮件地址,将定向到该公用文件夹。

I have tried writing a ExchangeManagementShell script to extract the e-mail addresses to a CSV file.我曾尝试编写 ExchangeManagementShell 脚本以将电子邮件地址提取到 CSV 文件。 The command to extract them does what I want it to do in the powershell window but when it goes in to a CSV it just shows a line of text that doesn't mean anything.提取它们的命令在 powershell 窗口中执行我希望它执行的操作,但是当它进入 CSV 时,它只显示一行没有任何意义的文本。

Get-MailPublicFolder |Select Displayname, Emailaddresses | export-csv -Path $env:userprofile\Desktop\mail-enabled-public-folders.csv

all I get is我得到的只是

 "27c87ef9bbda4f709f6b4002fa4af63c",,,,,

repeated 49 times.重复了 49 次。

Any help would be appriciated.任何帮助将被appriciated。

I found it depends on where you run the script.我发现这取决于您运行脚本的位置。 If run from an on-premise Exchange server, the Emailaddresses property is a Microsoft.Exchange.Data.SmtpProxyAddressCollection , whereas running this remotely you will receive a System.Collections.ArrayList .如果从本地 Exchange 服务器运行,则Emailaddresses属性是Microsoft.Exchange.Data.SmtpProxyAddressCollection ,而远程运行它时,您将收到System.Collections.ArrayList

Try the code below:试试下面的代码:

    $result = Get-MailPublicFolder -ResultSize Unlimited -ErrorAction SilentlyContinue | 
        ForEach-Object {
            $primary = $_.PrimarySmtpAddress
            if ($_.EmailAddresses -is [System.Collections.ArrayList]) {
                # using a remote connection, this is a System.Collections.ArrayList
                # containing address strings with 'smtp:' of 'SMTP:' prefix
                $aliases = ($_.EmailAddresses | Where-Object { $_ -cmatch '^smtp:' }) | 
                           ForEach-Object { $_ -replace '^smtp:'}
            }
            else {
                # when run on an on-premise Exchange server, this is a 
                # Microsoft.Exchange.Data.SmtpProxyAddressCollection
                # where every object has these properties:
                    #   SmtpAddress        : address@company.com
                    #   AddressString      : address@company.com
                    #   ProxyAddressString : smtp:address@company.com
                    #   Prefix             : SMTP
                    #   IsPrimaryAddress   : False
                    #   PrefixString       : smtp
                $aliases = $_.EmailAddresses | 
                           Where-Object { !$_.IsPrimaryAddress -and $_.PrefixString -eq 'smtp' } | 
                           Select-Object -ExpandProperty AddressString
            }

            # output an object to be collected in variable $result
            [PsCustomObject]@{            
                DisplayName           = $_.DisplayName
                'PrimaryEmailAddress' = $primary
                'EmailAlias'          = $aliases -join '; '
            }
        }

# output on screen
$result | Format-Table -AutoSize  # or use Format-List if you like that output better

# output to CSV file
$fileOut = Join-Path -Path $env:USERPROFILE -ChildPath 'Desktop\mail-enabled-public-folders.csv'
$result | Export-Csv -Path $fileOut -Encoding UTF8 -NoTypeInformation -Force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM