简体   繁体   English

O365,使用 Powershell 管理分发列表组

[英]O365, Manage Distribution List group with Powershell

Hope you're having a great day so far, I'm using O365 Online, and I'm trying to Add a user to a distribution list group with Powershell. to automate user creation.希望你到目前为止过得愉快,我正在使用 O365 Online,我正在尝试使用 Powershell 将用户添加到通讯组列表组以自动创建用户。 here are my steps这是我的步骤

  1. Connect to MolService: Connect-MsolService连接到 MolService: Connect-MsolService

  2. I get the ObjectID of the distribution group.我得到通讯组的ObjectID

    $GroupeID = Get-MsolGroup -ObjectId $SupervisorGroup.ObjectId

  3. I get the user ObjectID我得到用户 ObjectID

ObjectIDUser = Get-MsolUser -ObjectId $user.ObjectId

  1. I'm adding the user to the group我正在将用户添加到组中

Add-MsolGroupMember -GroupObjectId $GroupeID.ObjectId -GroupMemberObjectId $Object.ObjectId -GroupMemberType User

But here is the error:但这是错误:

Add-MsolGroupMember : You cannot update mail-enabled groups using this cmdlet. Use Exchange Online to perform 
this operation.
At line:11 char:2
+  Add-MsolGroupMember -GroupObjectId $GroupeID.ObjectId -GroupMemberOb ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Add-MsolGroupMember], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.MailEnabledGroupsNotSupportedException 
   ,Microsoft.Online.Administration.Automation.AddGroupMember

As the error states: You cannot use the MSOL Cmdlets with Mail Enabled Objects, Use the Exchange Online Cmdlets for that:如错误所述:您不能将 MSOL Cmdlet 与启用邮件的对象一起使用,为此请使用 Exchange Online Cmdlet:

Here's an helper function to load the Office 365 Exchange Cmdlets:这是加载 Office 365 Exchange Cmdlet 的助手 function:

Function Load-365ExchangeShell
{
Param(
[System.Management.Automation.PSCredential]
$Cred
)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -WarningAction SilentlyContinue -DisableNameChecking
}

Use it like this:像这样使用它:

$Cred = Get-Credential
Load-365ExchangeShell -Cred $Cred

Then use the relevant cmdlet ( Add-DistributionGroupMember ):然后使用相关的 cmdlet ( Add-DistributionGroupMember ):

Add-DistributionGroupMember -Identity "DistributionGroupID_here" -Member "UserToAddID_here"

Note: for future use you better use the Updated Exchange Online V2 Module instead of the above method, as the old commands are deprecated...注意:为了将来使用,您最好使用更新的 Exchange Online V2 模块而不是上述方法,因为旧命令已弃用...

See this link看到这个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM