【发布时间】:2020-03-19 20:37:26
【问题描述】:
我有下面的代码,它不是很有效,希望得到任何建议。我有基本的 powershell 编码技能,所以如果我的陈述完全错误,请原谅我。我正在尝试根据有效的部门变量来获取用户,然后将每个用户添加到无效的共享邮箱中。我认为问题在于变量或 for 循环,因为手动运行的命令可以正常工作。
提前谢谢你。
$UserCredential = Get-Credential
$Session = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionURI https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential –Authentication Basic –AllowRedirection
Set-ExecutionPolicy Unrestricted
Import-PSSession $Session
Import-Module msonline
Connect-MsolService -Credential $UserCredential
$DL = Get-MsolUser -All -Department "Staff" | select-object UserPrincipalName
ForEach ($UserPrincipalName in $DL) {
$DL | % {Add-MailboxPermission "shared-mailbox@domain.com"} -User $_ -AccessRights FullAccess -InheritanceType All}
Remove-PSSession $Session
【问题讨论】:
标签: powershell office365