尝试使用 Powershell 从全局地址列表中删除所有未经许可的用户

Trying to remove all unlicensed users from the Global address list using Powershell

我正在尝试从全局地址列表中删除所有未获得许可的用户。

到目前为止,我发现...

$mboxes = Get-MsolUser -All -UnlicensedUsersOnly

... 将获取所有未经许可的用户,并将它们放入名为 $mboxes 的变量中,但此处似乎没有身份。

因为当我尝试 运行 类似的东西时:

foreach ($mbox in $mboxes) { Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $mbox }

我收到以下错误。

Cannot process argument transformation on parameter 'Identity'.

我已经尝试将该数据导出到 CSV 并创建一个 "Identity" header,但是在 re-importing 将数据返回到 PowerShell 后我遇到了同样的问题。

您的解决方案非常接近。 来自 Set-Mail 文档:

The -Identity parameter specifies the mailbox that you want to modify. You can use any value that uniquely identifies the mailbox.

使用 $mbox.UserPrincipalName 传递用户主体名称。

$mboxes = Get-MsolUser -All -UnlicensedUsersOnly
foreach ($mbox in $mboxes) { Set-Mailbox -HiddenFromAddressListsEnabled $true -Identity $mbox.UserPrincipalName }