【问题标题】:PowerShell 365 - Remove-UnifiedGroupLinks convert value errorPowerShell 365 - Remove-UnifiedGroupLinks 转换值错误
【发布时间】:2020-12-27 00:07:55
【问题描述】:

我正在尝试清除 365 组的成员资格,但删除命令不接受通配符,因此选择使用“get-user”并将其放入“foreach”中。然而这个错误。你能帮忙吗?

#get list
$users = Get-UnifiedGroupLinks –Identity "testgroup" -LinkType Members
#empty list
    foreach($user in $users){
        Remove-UnifiedGroupLinks –Identity "testgroup" –LinkType "Members" –Links $user
    }

错误

Cannot process argument transformation on parameter 'Links'. Cannot convert value "System.Collections.ArrayList" to type "Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter[]". Error: "Cannot 
convert the "Mr User" value of type "Deserialized.Microsoft.Exchange.Data.Directory.Management.ReducedRecipient" to type "Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter"."
    + CategoryInfo          : InvalidData: (:) [Remove-UnifiedGroupLinks], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-UnifiedGroupLinks
    + PSComputerName        : outlook.office365.com

【问题讨论】:

  • 刚接触 SO 你可能不知道这一点,但习惯于点击左侧的 ✓ 图标 accept the answer that solved your problem。这将有助于其他有类似问题的人更轻松地找到它,并有助于激发人们回答您的问题。

标签: powershell office365 exchange-server


【解决方案1】:

Remove-UnifiedGroupLinks 上的 Links 参数指定要从 Microsoft 365 组中删除的用户。 它需要一个唯一标识收件人的值,为此您可以使用以下任何一种:

  • 姓名
  • 别名
  • 专有名称 (DN)
  • 规范 DN
  • 电子邮件地址
  • GUID

在您的代码中,您只需从Get-UnifiedGroupLinks 返回的成员对象中选择这样一个属性,例如用户的电子邮件地址。

试试

#get list
$users = (Get-UnifiedGroupLinks –Identity "testgroup" -LinkType Members).PrimarySMTPAddress
#empty list
foreach($user in $users){
    Remove-UnifiedGroupLinks –Identity "testgroup" –LinkType Members –Links $user
}

【讨论】:

  • @WillDavid 我很高兴它对你有用。如果您觉得我的回答解决了您的问题,请考虑通过单击左侧的 ✓ 图标来接受答案。见How to accept SO answers。这将帮助其他有类似问题的人更轻松地找到它。
【解决方案2】:

前面的答案可行,但另一种方法是在 foreach 循环内以不同的方式“即时”指定用户。由于您使用 Get-UnifiedGroupLinks 来拉入用户对象,因此您拉回了您可以使用的 $users 变量中的许多属性。您只需要在 foreach 循环中更加具体,并使用其中一个属性。

您可以像这样在 foreach 循环中为每个用户指定 PrimarySmtpAddress

    –Links $($user).PrimarySmtpAddress

我一直在研究一些用于管理团队/统一组的代码示例,并在一些 foreach 循环中使用了这种技术:Unsubscribe-FollowInInbox.ps1

如果您有任何问题,请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    相关资源
    最近更新 更多