使用 powershell 将电子邮件添加到 outlook 分发列表
Add an email to outlook distribution list using powershell
我只是按照以下脚本在 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()
AddMember
只允许传递一个 Recipient
对象作为参数:调用 Application.Session.CreateRecipient("manager@abc.com")
/ Recipient.Resolve
/ DistListItem.AddMember(Recipient).
如果需要直接添加联系人,可以使用Redemption (I am its author) and its RDODistListItem.AddContact
方法。
UPDATE: 在 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
我只是按照以下脚本在 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()
AddMember
只允许传递一个 Recipient
对象作为参数:调用 Application.Session.CreateRecipient("manager@abc.com")
/ Recipient.Resolve
/ DistListItem.AddMember(Recipient).
如果需要直接添加联系人,可以使用Redemption (I am its author) and its RDODistListItem.AddContact
方法。
UPDATE: 在 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