我只需按照脚本
在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"名字是"经理"
如何使用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.
请帮忙
[UPDATE] 现在我有一个有效的脚本:
$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()
答案 0 :(得分:2)
AddMember only allows to pass a Recipient object as a parameter: call Application.Session.CreateRecipient("manager@abc.com")
/ Recipient.Resolve
/ DistListItem.AddMember(Recipient).
If you need to add a contact directly, you can use Redemption and its RDODistListItem.AddContact method.
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