【问题标题】:Add an email to outlook distribution list using powershell使用 powershell 将电子邮件添加到 Outlook 分发列表
【发布时间】:2015-10-19 06:07:00
【问题描述】:

我只是通过以下脚本在 Outlook 上创建一个新的分发列表

$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”,名字是“manager”

如何使用 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()

【问题讨论】:

  • Add-DistributionGroupMember 不起作用,因为它是 Exchange cmdlet。您的前景中有一个本地组。大概您还需要使用Outlook.Application 来编辑它。您想在创建时添加还是事后添加?
  • 我想在事后添加它。尝试过这样的事情: $dl.AddMember($newcontact) 其中 $newcontact 是新创建的联系人。但仍然无法正常工作。

标签: email powershell outlook distribution-list contactgroups


【解决方案1】:

AddMember 只允许将 Recipient 对象作为参数传递:调用 Application.Session.CreateRecipient("manager@abc.com") / Recipient.Resolve / DistListItem.AddMember(Recipient).

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

更新:在 Redemption 中,以下代码将开关成员添加到新的 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

【讨论】:

  • 我做了这个 $r = $outlook.Session.CreateRecipient("manager@abc.com") $r.Resolve $dl.AddMember($r) $dl.save() 它没有错误,但新创建的列表仍然不包含任何内容。我做错什么了吗?
  • 你调用 DIstListItem.Save 吗?
  • 也尝试过类似的方法:set $Session = CreateObject("Redemption.RDOSession")/ $Session.Logon/ set $Contacts = Session.GetDefaultFolder($olFolderContacts)/ set $DL = Contacts. Items.Add("IPM.DistList")/ $DL.DLName = "赎回测试"/ $DL.AddMember("test ")/ $DL.Save/
  • 这给出了一个错误 Set-Variable : Cannot bind argument to parameter 'Name' because it is null.
  • 第 1 行:设置 $Session = CreateObject("Redemption.RDOSession")
猜你喜欢
  • 1970-01-01
  • 2010-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-15
  • 2021-07-16
相关资源
最近更新 更多