【问题标题】:Exchange Powershell: Contacts from Public FolderExchange Powershell:公用文件夹中的联系人
【发布时间】:2012-11-01 07:03:21
【问题描述】:

Exchange 命令行管理程序:

[PS] C:\Windows\system32>$AddressBook = Get-PublicFolderItemStatistics -Identity "\Shared Company Address Book"

[PS] C:\Windows\system32>$AddressBook [0] | format-list

RunspaceId           : d8e95055-1f3e-4e7f-a1fc-d5b97ecbcb96
ServerName           : MAILMAN
DatabaseName         : Public Folder Database 0524088380
Subject              : John Q User
PublicFolderName     : \Company Address Book
LastModificationTime : 11/12/2012 2:57:49 PM
CreationTime         : 11/12/2012 2:56:28 PM
HasAttachments       : False
ItemType             : IPM.Contact
MessageSize          : 6.598 KB (6,756 bytes)
Identity             : 000000001A447390AA6611CD9BC800AA002FC45A0900580787449ABF5E4891DD89178938242C0000000250AE00001BE1
                       A5309D57D5439914FD70BDC745C100000B8942FD0000
MapiIdentity         : 000000001A447390AA6611CD9BC800AA002FC45A0900580787449ABF5E4891DD89178938242C0000000250AE00001BE1
                       A5309D57D5439914FD70BDC745C100000B8942FD0000
OriginatingServer    : mailman.company.com
IsValid              : True

[PS] C:\Windows\system32>

好的...我正在尝试在 Exchange Server 2010 联系人列表中导出联系人。就我个人而言,我无法弄清楚如何从这个愚蠢的东西中获取“数据”。

如果我这样做 $AddressBook | Format-List,它列出了所有的联系人,所以我知道我在正确的球场。

我怎样才能从这个列表中获取所有信息?姓氏、名字、电子邮件地址、商务电话等

【问题讨论】:

    标签: powershell contacts powershell-2.0 exchange-server exchange-server-2010


    【解决方案1】:

    这是一个旧帖子,但我有几天同样的问题,无法弄清楚。因此,我选择使用 @WernerCD 使用的路径,并希望添加我的 PowerShell 脚本,以便在您决定走这条路的情况下为您提供帮助。

    在开始之前,请允许我解释一下我的问题。我们有多个包含联系人的文件夹。这些联系人包含由于迁移问题而未添加到其包含文件夹的用户定义字段。当我们使用 Outlook 时,我们需要能够在当前视图中看到这些字段。但是,当我们尝试添加 UDF 列时,它只允许我们使用“文件夹中的用户定义字段”,它是空的。

    下面是 PowerShell 脚本,它将检查 Outlook 中的公用文件夹(及其子文件夹),检查每个联系人的 UserProperties(相当于 UDF),将它们放入一个数组中,然后它将检查每个联系人的 UDF 是否存在于其包含文件夹(UserDefinedProperties),如果不存在,则将其添加为没有值的文本字段。

    请记住,我们所有的联系人文件夹都在一个名为 Shared Contacts Folder 的文件夹下。

    代码

    # Connection to Outlook
    $Outlook       = New-Object -com Outlook.Application 
    $Namespace     = $outlook.GetNamespace("MAPI") 
    
    # "Location" of public folders (Change me@example.com)
    $PublicFolder  = $Namespace.Folders.Item("Public Folders - me@example.com")
    $PublicFolders = $PublicFolder.Folders.Item("All Public Folders")
    
    # Folder that you would like to check. We will check Shared Contacts under Shared Contacts Folder
    $SharedContactsFolder   = $PublicFolders.Folders.Item("Shared Contacts Folder")
    $SharedContacts   = $SharedContactsFolder.Folders.Item("Shared Contacts")
    
    Write-Host ("<----------------------------------------------------------->") -foreground Yellow
    
    function CheckContacts($MyFolder){
    
        # Check if this folder has subfolder
        If ( $MyFolder.Folders.Count -gt 0) {
    
            Write-Host ("Folder '" + $MyFolder.Name + "' contains subfolders ("  + $MyFolder.Folders.Count + ")")  -BackgroundColor Yellow -foreground DarkBlue
    
            Foreach ( $Subfolder in $MyFolder.Folders ) {
    
                CheckContacts($Subfolder)
    
            }
    
        }
    
        Write-Host ("Working on folder: " + $MyFolder.Name)  -BackgroundColor White -foreground DarkBlue
    
        $All_UDF = @()
    
        # Check User Defined Fields (UDF) for each contact and add them to array
        foreach ( $Contacts in $MyFolder.Items ) {
    
            foreach ( $UDF in $Contacts.UserProperties ) {
    
                # Check if field was previously added to array
                If ($All_UDF -notcontains $UDF.Name) {
                    $All_UDF += $UDF.Name
                }
    
            }
    
        }
    
        # Add all UDF to Folder's UDF
        Write-Host ("We will add the following UDF into '" + $MyFolder.Name + "': ") -foreground Green
        Write-Host ($All_UDF -join "`n") -foreground Green
    
        Foreach ( $UDF in $All_UDF ){
    
            # Only add if UDF does not exist on folder's UDF
            if( (CheckFolderUDF $MyFolder $UDF) -eq $false) {
                # Add - Always add UDF as Text field (1)
                Write-Host ("Adding '" + $UDF + "' to '" + $MyFolder.Name + "'")
                $MyFolder.UserDefinedProperties.Add($UDF, 1)
            }else{
                Write-Host ("Already present: " + $UDF)
            }
    
        }
    
        Write-Host ("<----------------------------------------------------------->") -foreground Yellow
    }
    
    Function CheckFolderUDF ( $MyFolder, $MyUDFName ) {
        $Result = $false
    
        Foreach ( $Folder_UDF in $MyFolder.UserDefinedProperties ){
    
            If ( $Folder_UDF.Name -eq $MyUDFName ) {
                $Result = $true
                break
            }
    
        }
    
        return $Result
    
    }
    
    # Start - Check Shared Contacts
    CheckContacts($SharedContacts) 
    

    如何运行/测试这段代码?

    1) 打开 Windows PowerShell ISE(在 Windows 中)。

    2) 复制上面的代码并将其粘贴到 PowerShell ISE 窗口中。

    3) 阅读并理解代码。

    4) 根据需要进行修改。

    P.S.:我试图添加这个“评论”,但我没有足够的积分。

    【讨论】:

      【解决方案2】:

      在经历了许多痛苦和磨难之后……偶然发现了[this post]。这是在 Powershell(不是 Exchange Powershell 控制台)和我的计算机(不是服务器 MailMan)中:

      $Outlook       = New-Object -com Outlook.Application 
      $Namespace     = $outlook.GetNamespace("MAPI") 
      $PublicFolder  = $Namespace.Folders.Item("Public Folders - me@example.com")
      $PublicFolders = $PublicFolder.Folders.Item("All Public Folders")
      $AddressBook   = $PublicFolders.Folders.Item("Company Address Book")
      $Contacts      = $AddressBook.Items
      $Contacts | Select FullName
      

      这实际上提取了联系信息。我仍在研究如何在服务器端(Exchange Powershell 控制台)执行此操作,但这应该是选择所需字段并根据需要将它们推送到数据库中的良好基础。

      我想如果我能弄清楚如何获取“公共文件夹 - dummy_user@example.com”,我应该能够在服务器上做同样的事情。

      我还假设有一种更简单的方法可以做到这一点(可能是通过拉路径,而不是一次一个部分),但这确实有效。

      现在来了解如何获取 UserDefinedFields....

      【讨论】:

        【解决方案3】:

        为什么不使用Get-Contact 而不是Get-PublicFolderItemStatistics

        【讨论】:

        • 如何让 Get-Contact 从“公共文件夹”/地址簿中提取?在 Outlook 中,我们有一个“公共”通讯簿,它显示在我的 Outlook 应用程序联系人选项卡中的“其他联系人”下。这些联系人卡片不会出现在 Get-Contact 上。据我所知,这些卡片很可能与 Active Directory 帐户(确实显示在 Get-Contact 中)没有关联。
        • 是的,但是您可以在 $addressbook 和 Identity 参数中使用 foreach 循环? $地址簿 | % { 获取联系 $_.Identity |选择 [字段] | Out-GridView } ? (我现在不在工作,所以我无法测试 Exchange 代码。这让我无法理解)也许我误解了这个请求,如果是这样,我很抱歉。
        • 打开 Outlook。然后打开联系人选项卡。我有两个组:我的联系人和其他联系人。在“其他联系人”中是一个文件夹“我的公司通讯录”。这是约 1000 张“联系卡”。我正在尝试通过 Exchange Powershell 获取这些联系人卡片。
        • 尝试 $Book | % { Get-Contact $_.Identity } 给出错误:无法处理参数“Identity”的参数转换。不能转换“000000001A447390AA6611CD9BC800AA002FC45A0900580787449ABF5E4891DD89178938242C0000000250AE00001BE1A5309D57D5439914FD70BDC745C1000007DF796D0000”类型的值“Microsoft.Exchange.Data.Mapi.MessageId”到“Microsoft.Exchange.Configuration.Tasks.ContactIdParameter” 跨度>
        • 添加了我自己的答案。应该从服务器端(而不是在用户...也就是我的...计算机上)更好地了解我在寻找什么
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-08
        • 1970-01-01
        • 2016-12-12
        • 2015-04-02
        • 1970-01-01
        • 2015-03-18
        相关资源
        最近更新 更多