繁体   English   中英

Office 365通过Powershell批量添加共享邮箱成员

[英]office 365 bulk add shared mailbox members via powershell

我已经在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
}

有什么想法吗 ?

连接到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添加用户

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM