【问题标题】:office 365 bulk add shared mailbox members via powershelloffice 365通过powershell批量添加共享邮箱成员
【发布时间】:2018-11-14 21:34:12
【问题描述】:

我已经在 o365 中创建了共享邮箱。 现在我需要将成员批量导入这些共享邮箱。

如何在 powershell 中做到这一点? 我想做这样的事情

$users = import-csv -Path "C:\path\members.csv" -Delimiter ";"
Foreach ($user in $users){
    Add-mailboxpermission -identity "name of the shared mail box" -user $user -accessrights FullAccess
}

有什么想法吗?

【问题讨论】:

  • 请显示您的一些(清理)csv 内容。你有标题吗?

标签: powershell office365


【解决方案1】:

连接到 Office365 将是一个很好的第一步:

$AdminUsername = "admin@your-domain.onmicrosoft.com" 
$AdminPassword = "YourPassword"
$AdminSecurePassword = ConvertTo-SecureString -String "$AdminPassword" -AsPlainText -Force
$AdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminUsername,$AdminSecurePassword

$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $Admincredential -Authentication "Basic" -AllowRedirection
Import-PSSession $ExchangeSession

会话结束后,您可以使用函数并添加一些逻辑:

$access = "FullAccess"
$mailbox = Get-Mailbox -Identity YourMailbox
$identity = $mailbox.UserPrincipalName
$permissions = Get-MailboxPermission -identity $identity

$users = Import-Csv -Path "C:\path\members.csv" -Delimiter ";" 
foreach($user in $users){
    try{
        $setPermissions = Add-MailboxPermission -Identity $identity -User $user -AccessRights $access
        Write-Host "Successfully added permissions for $user" -ForegroundColor Green
    }catch{
        Write-Host "Failed to add permissions for $user" -ForegroundColor Red
    }
}

记得根据 UserPrincipalName 添加用户

【讨论】:

  • 问题还存在吗?我提供的脚本不起作用吗?如果我能帮助你,请告诉我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-15
  • 2016-10-29
  • 1970-01-01
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多