office 365通过PowerShell批量添加共享邮箱成员
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了office 365通过PowerShell批量添加共享邮箱成员相关的知识,希望对你有一定的参考价值。
我已经在o365中创建了共享邮箱。现在我需要将成员批量导入这些共享邮箱。
如何在powershell中做到这一点?我想做这样的事情
$users = import-csv -Path "C:pathmembers.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:pathmembers.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添加用户
以上是关于office 365通过PowerShell批量添加共享邮箱成员的主要内容,如果未能解决你的问题,请参考以下文章
如何使用Powershell为office 365用户批量分配许可证
powershell [Manipulandousuários通过PowerShell执行Office 365] Comandos para manipular o Office 365.