代码之家  ›  专栏  ›  技术社区  ›  Tempuslight

尝试运行脚本,使用Exchange Online,连接工作,Get UnifiedGroup工作,但集合不存在?

  •  0
  • Tempuslight  · 技术社区  · 6 年前

    $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
    

    这将隐藏所有与sharepoint URL连接的电子邮件地址,以防创建团队网站。不管怎样,使用UnifiedGroup works,但是当我执行以下操作时:

    Set-UnifiedGroup -HiddenFromAddressListsEnabled $true  
    

    上面写着:

    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  
    

    Install-Module MSOnline  
    

    我不知道该去哪里找了,我不习惯写Powershell。。。

    1 回复  |  直到 6 年前
        1
  •  1
  •   CraftyB    6 年前

    查看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脚本的用户添加到成员列表中。