添加电子邮件使用PowerShell前景分发列表(Add an email to outlook d

2019-10-24 06:15发布

我刚刚创建Outlook中新通讯组列表BYT他下面的脚本

$outlook = new-object -com Outlook.Application
$contacts = $outlook.Session.GetDefaultFolder(10)
$dl = $contacts.Items.Add("IPM.DistLIst")
$dl.DLName = "Group A"
$dl.Save()

我有一个电子邮件地址“manager@abc.com”与名称为“经理”

我如何使用PowerShell将它添加到新创建的通讯组列表?

我必须使用PowerShell由于某些原因,我已经尝试过这样的:

Add-DistributionGroupMember -Idneity "Group A" -Member "manager@abc.com"

但是,给出了这样的错误:

The term 'Add-DistributionGroupMember' is not recognized as the name of a cmdlet, function, 
script file, or operable program.

请帮忙

[更新]现在我有一个脚本,工作原理:

  $outlook = new-object -com Outlook.Application
  $contacts = $outlook.Session.GetDefaultFolder(10)
  $session = $outlook.Session
  $session.Logon("Outlook")
  $namespace = $outlook.GetNamespace("MAPI")
  $recipient = $namespace.CreateRecipient("John Smith@abc.com")  # this has to be an exsiting contact
  $recipient.Resolve()  # check if this returns true
  $DL = $contacts.Items.Add("IPM.DistList")
  $DL.DLName = "test dl"
  $DL.AddMember($recipient)
  $DL.Save()

Answer 1:

使用addMember只允许通过一个收件人对象作为参数:呼叫Application.Session.CreateRecipient("manager@abc.com") / Recipient.Resolve / DistListItem.AddMember(Recipient).

如果你需要直接添加联系人,你可以用赎回及其RDODistListItem .AddContact方法。

更新:在救赎,下面的代码添加了一个开关成员到新DL列表:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Contacts = Session.GetDefaultFolder(olFolderContacts)
  set DL = Contacts.Items.Add("IPM.DistList")
  DL.DLName = "test dl"
  DL.AddMember("test@dimastr.com")
  DL.Save


文章来源: Add an email to outlook distribution list using powershell