
Outlook の GUI を使用して受信トレイ ルールを作成、削除、管理しようとするのはうんざりです。時間がかかり、面倒です。
PowerShell には、サーバー側でもクライアント側でもこれを実行できるコマンドレットがあることは理解しています。
サーバー側へのアクセス権はなく、これらのルールを使用して自分の受信トレイを管理することにのみ興味があります。
次の記事には、これに最適なコマンドレットがいくつか記載されているようですが、ライブラリをどこからインポートすればよいかわからないため、使用できません。
https://www.codetwo.com/admins-blog/managing-outlook-rules-powershell/
最初にコマンドレットをインストールするにはどうすればよいですか? コマンドレットはどこで入手できますか? また、スクリプトにインポートするには何が必要ですか?
答え1
コメント欄には長すぎるのでここに投稿します。
メールボックスを管理するということは、スタンドアロン クライアント (ファット、クラウド、またはその両方 - Outlook ファット クライアントに Outlook.com アカウントを直接追加できることを覚えておいてください) で自分だけを対象にしているのか、それとも企業内のユーザーを対象にしているのかという問題です。
ローカル Outlook を制御するために Exchange コマンドレットは使用しません。Exchange コマンドレットを使用するには、コンピューターに Exchange 管理シェルをインストールする必要があります...
...または、PowerShell の暗黙的なリモート処理を使用して、これらのコマンドレットをホストにプロキシします。暗黙的なリモート処理は、O365 の Exchange コマンドレットを使用する方法でもあります。これらは、Microsoft や Web 上の多数のブログ、YouTube ビデオによって詳細に文書化されています。
この作業のために事前に構築されたモジュールもあります。
PowerShell を使用して Office 365 サービスに接続する
Office 365 または Exchange On-Premises に接続するためのヘルパー関数を備えた PowerShell スクリプト。同じ資格情報 (非 MFA) を使用して、さまざまな Office 365 サービスに簡単に接続できます。各ワークロードに接続するためのさまざまな方法を覚えておく必要がなくなります。
Outlookオンラインには、Exchange、EWSと同様にREST APIが用意されています。
Outlook クライアント
Outlook REST API を使用すると、Office 365 または outlook.com のユーザーがメール、予定表、連絡先データに簡単にアクセスできます。このビデオでは、API の V2.0 で導入された主要な機能のいくつか (Webhook、写真、リマインダー、タイムゾーン) について説明します。
PowerShell を使用して Outlook の受信トレイをデータマイニングする
# Get-OutlookInBox function
Function Get-OutlookInBox
{
<#
.Synopsis
This function returns InBox items from default Outlook profile
.Description
This function returns InBox items from default Outlook profile. It
uses the Outlook interop assembly to use the olFolderInBox enumeration.
It creates a custom object consisting of Subject, ReceivedTime, Importance,
SenderName for each InBox item.
*** Important *** depending on the size of your InBox items this function
may take several minutes to gather your InBox items. If you anticipate
doing multiple analysis of the data, you should consider storing the
results into a variable, and using that.
.Example
Get-OutlookInbox |
where { $_.ReceivedTime -gt [datetime]”5/5/11″ -AND $_.ReceivedTime -lt `
[datetime]”5/10/11″ } | sort importance
Displays Subject, ReceivedTime, Importance, SenderName for all InBox items that
are in InBox between 5/5/11 and 5/10/11 and sorts by importance of the email.
.Example
Get-OutlookInbox | Group-Object -Property SenderName | sort-Object Count
Displays Count, SenderName and grouping information for all InBox items. The most
frequently used contacts appear at bottom of list.
.Example
$InBox = Get-OutlookInbox
Stores Outlook InBox items into the $InBox variable for further
“offline” processing.
.Example
($InBox | Measure-Object).count
Displays the number of messages in InBox Items
.Example
$InBox | where { $_.subject -match ‘2011 Scripting Games’ } |
sort ReceivedTime -Descending | select subject, ReceivedTime -last 5
Uses $InBox variable (previously created) and searches subject field
for the string ‘2011 Scripting Games’ it then sorts by the date InBox.
This sort is descending which puts the oldest messages at bottom of list.
The Select-Object cmdlet is then used to choose only the subject and ReceivedTime
properties and then only the last five messages are displayed. These last
five messages are the five oldest messages that meet the string.
.Notes
NAME: Get-OutlookInbox
AUTHOR: ed wilson, msft
LASTEDIT: 05/13/2011 08:36:42
KEYWORDS: Microsoft Outlook, Office
HSG: HSG-05-26-2011
.Link
Http://www.ScriptingGuys.com/blog
#Requires -Version 2.0
#>
Add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null
$olFolders = “Microsoft.Office.Interop.Outlook.olDefaultFolders” -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace(“MAPI”)
$folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)
$folder.items |
Select-Object -Property Subject, ReceivedTime, Importance, SenderName
} #end function Get-OutlookInbox
これを実行するには、O365 の管理者である必要があります。デスクトップ上の Outlook が Exchange ではないのと同様に、O365 の Outlook は Exchange ではありません。Outlook クライアントで作業するには、Outlook COM (上記および後述) を使用する必要があります。これは、オンラインでは当てはまりません。
PowerShell で Outlook アドレスを取得する
答え2
私の知る限り、Outlook で使用できる標準の PowerShell モジュールはありませんが、Microsoft.Office.Interop.Outlook
名前空間へのアクセスを提供する Outlook API を利用することはできます。新しいルールを作成する簡単な例は次のとおりです。
まず、名前空間を取得します。
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
ここで、元のフォルダ(受信トレイ)を指定し、新しいルールを作成し、コピー先のフォルダ(通知)を指定します。
$inbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$MyFolder1 =
$namespace.Folders.Item('[email protected]').Folders.Item('NOTIFICATIONS')
$rules = $namespace.DefaultStore.GetRules()
$rule = $rules.create("My rule1: Receiving Notification",
[Microsoft.Office.Interop.Outlook.OlRuleType]::olRuleReceive)
$rule_body = $rule.Conditions.Subject
$rule_body.Enabled = $true
$rule_body.Text = @('Completed Notification')
$action = $rule.Actions.CopyToFolder
$action.enabled = $true
[Microsoft.Office.Interop.Outlook._MoveOrCopyRuleAction].InvokeMember(
"Folder",
[System.Reflection.BindingFlags]::SetProperty,
$null,
$action,
$MyFolder1)
$rules.Save()
PowerShell で Outlook 名前空間を使用する方法の詳細な例と情報については、以下を参照してください。 https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/march/powershell-managing-an-outlook-mailbox-with-powershell
さらに、Outlook オブジェクト モデルに関するすべての情報は、次の場所で確認できます。 https://docs.microsoft.com/nl-nl/office/vba/api/overview/Outlook/オブジェクトモデル