これは古い投稿ですが、数日間同じ問題があり、理解できませんでした。そこで、@WernerCD が使用した道を使用することを選択し、この道を進むことにした場合に役立つ PowerShell スクリプトを追加したいと思います。
始める前に、私の問題を説明させてください。連絡先が含まれる複数のフォルダーがあります。これらの連絡先には、移行の問題が原因で含まれるフォルダーに追加されなかったユーザー定義フィールドが含まれています。Outlook を使用している間、現在のビューでこれらのフィールドを表示できる必要があります。ただし、UDF 列を追加しようとすると、空の「フォルダー内のユーザー定義フィールド」しか使用できません。
以下は、Outlook 内のパブリック フォルダー (およびそのサブフォルダー) をチェックし、すべての連絡先の UserProperties (UDF に相当) をチェックし、それらを配列に入れ、各連絡先の UDF が含まれているフォルダー (UserDefinedProperties) に存在するかどうかをチェックする PowerShell スクリプトです。 )、存在しない場合は、値のないテキスト フィールドとして追加されます。
すべての連絡先フォルダーは、共有連絡先フォルダーと呼ばれるフォルダーの下にあることに注意してください。
コード
# 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) 必要に応じて変更します。
PS: これに「コメント」を追加しようとしましたが、十分なポイントがありません。