Добавьте электронное письмо в список рассылки outlook с помощью 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" с именем, чтобы быть "менеджером"
Как использовать 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()
1 ответ
AddMember позволяет только передать объект Recipient в качестве параметра: call 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