所以我有这个脚本,我一直用来查找/删除重复的Outlook联系人。我在这个脚本上取得了成功,但最近开始出现错误。我不是Powershell专家,也不是我声称能够精通它,所以我绊倒了我的方式。只是寻找一些意见或想法,为什么这个轰炸...获得独特的项目
脚本
#########################################################
# #
# Remove Duplicate Outlook Contacts by Jean Louw #
# Blog http://powershellneedfulthings.blogspot.com/ #
# #
#########################################################
$olSession = (New-Object -ComObject Outlook.Application).Session
$olSession.Logon('Outlook') #Outlook is the profile name
$contactsFolder = 10
$tempFolderName = 'temp_folder_' + (get-date -Format ddmmyyyhhmmss)
$myContacts = $olSession.GetDefaultFolder($contactsFolder).Items
$tempFolder = $olSession.GetDefaultFolder($contactsFolder).Folders.Add($tempFolderName)
Write-Host "..getting unique items"
$uniqueContacts = $myContacts | Sort FullName -Unique
#move contacts to temp contacts folder
foreach ($Contact in $uniqueContacts) {
$Contact.Move($tempFolder) | foreach-object {Write-Progress "Backup unique items to temp folder..." $_.FullName; $_.FullName} | Out-Null}
#read default contacts again and dump to csv
Write-Host "..export duplicates to csv"
$duplicates = $olSession.GetDefaultFolder($contactsFolder).Items
$duplicates | Export-Csv duplicates.csv
#delete all contacts left in default contacts folder
Foreach ($duplicate in $duplicates){
$duplicate.Delete() | foreach-object {Write-Progress "Deleting duplicate..." $_.FullName; $_.FullName} | Out-Null}
输出
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Windows\system32> $olSession = (New-Object -ComObject Outlook.Application).Session
PS C:\Windows\system32> $olSession.Logon('Outlook') #Outlook is the profile name
PS C:\Windows\system32> $contactsFolder = 10
PS C:\Windows\system32> $tempFolderName = 'temp_folder_' + (get-date -Format ddmmyyyhhmmss)
PS C:\Windows\system32> $myContacts = $olSession.GetDefaultFolder($contactsFolder).Items
PS C:\Windows\system32> $tempFolder = $olSession.GetDefaultFolder($contactsFolder).Folders.Add($tempFolderName)
PS C:\Windows\system32> Write-Host "..getting unique items"
..getting unique items
PS C:\Windows\system32> $uniqueContacts = $myContacts | Sort FullName -Unique
An error occurred while enumerating through a collection: Exception from HRESULT: 0x8837000E.
At line:1 char:18
+ $uniqueContacts = <<<< $myContacts | Sort FullName -Unique
+ CategoryInfo : InvalidOperation (System.Runtime....ewOfEnumVariant:EnumeratorViewOfEnumVariant) [], RuntimeException
+ FullyQualifiedErrorId : BadEnumeration
PS C:\Windows\system32>