使用powershell向Outlook的发布列表添加电子邮件 [英] Add an email to outlook distribution list using powershell

查看:630
本文介绍了使用powershell向Outlook的发布列表添加电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在Outlook上创建一个新的通讯组列表,其他脚本

I just create a new distribution list on Outlook byt he following script

$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

and I Have an e-mail address "manager@abc.com" with name to be "manager"

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

how do i use powershell to add this to the newly created distribution list?

由于某些原因我必须使用powershell,我已经尝试过:

I have to use powershell due to some reason, and I have tried this:

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

但是提供了这个错误: p>

But gives this error:

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

请帮助

[更新]
现在我有一个脚本:

[UPDATE] Now I have a script that works:

  $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()


推荐答案

AddMember只允许将收件人对象传递为一个参数:调用 Application.Session.CreateRecipient(manager@abc.com) / Recipient.Resolve / DistListItem.AddMember(收件人)。

AddMember only allows to pass a Recipient object as a parameter: call Application.Session.CreateRecipient("manager@abc.com") / Recipient.Resolve / DistListItem.AddMember(Recipient).

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

If you need to add a contact directly, you can use Redemption and its RDODistListItem.AddContact method.

更新:在兑换中,以下代码将一个开关成员添加到一个新的DL列表:

UPDATE: In Redemption, the following code adds a on-off member to a new DL list:

  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

这篇关于使用powershell向Outlook的发布列表添加电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆