尝试使用Exchange Online运行脚本时,连接有效,Get-UnifiedGroup有效,但是Set不存在吗?

时间:2018-09-20 10:53:07

标签: powershell outlook office365

因此,我正在尝试运行一个脚本,该脚本从客户的Outlook地址簿中隐藏某些电子邮件地址。

UITableViewCell

这将从创建团队站点中隐藏所有具有共享点URL的电子邮件地址。无论如何,Get-UnifiedGroup都可以,但是当我执行以下操作时:

$Username = "xxx"
$Password = "xxx" | ConvertTo-SecureString -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Get-UnifiedGroup -ResultSize Unlimited | Where-Object {$_.SharePointSiteUrl} | select PrimarySmtpAddress, SharePointSiteUrl | Set-UnifiedGroup -HiddenFromAddressListsEnabled $true 
Remove-PSSession $Session

它说:

Set-UnifiedGroup -HiddenFromAddressListsEnabled $true  

我已经搜索过google,但似乎找不到解决我问题的合适方法...我也做了以下命令,无济于事:

Set-UnifiedGroup: The term 'Set-UnifiedGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.  

Set-ExecutionPolicy RemoteSigned  

我不知道要看哪里,我也不是习惯于编写Powershell ...

1 个答案:

答案 0 :(得分:1)

查看Microsoft文档“ Set-UnifiedGroup -HiddenFromAddressListsEnabled”不会接受管道输入。

https://docs.microsoft.com/en-us/powershell/module/exchange/users-and-groups/set-unifiedgroup?view=exchange-ps

我建议尝试:

$Username = "xxx"
$Password = "xxx" | ConvertTo-SecureString -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
$groups = Get-UnifiedGroup -ResultSize Unlimited | Where-Object {$_.SharePointSiteUrl} | select PrimarySmtpAddress, SharePointSiteUrl

foreach ($group in $groups){
    set-unifiedgroup -identity $group.PrimarySmtpAddress -HiddenFromAddressListsEnabled $true
}

Remove-PSSession $Session

关于“ Set-UnifiedGroup:术语'Set-UnifiedGroup'不被识别为cmdlet的名称”

您将需要在Exchange管理中心中添加适当的角色,才能访问该cmdlet。

您需要成为管理员才能进行这些更改;

https://outlook.office365.com/ecp/?rfr=Admin_o365

登录并在左侧选择“权限”。

我认为“组织管理”应该为您提供所需的cmdlet。

编辑该角色,并将您用于上述Powershell脚本的用户添加到成员列表中。

这通常需要30-60分钟才能生效。