現在我有一個功能可以從單個用戶中洗掉多個共享電子郵件。但是,我希望能夠指定多個用戶也需要從他們的帳戶中洗掉多個共享電子郵件。我想不出一個好的方法來做到這一點?
這是我到目前為止所擁有的并且它有效,但我只能在 -user 引數上指定一個用戶。
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]$address,
[Parameter(Mandatory = $true)]
[string]$user
)
foreach ($mailbox in $address) {
Remove-MailboxPermission `
-Identity $mailbox `
-AccessRights FullAccess `
-Confirm:$false `
-User $user
Remove-RecipientPermission `
-Identity $mailbox `
-AccessRights SendAs `
-Confirm:$false `
-Trustee $user
Set-Mailbox $mailbox -GrantSendOnBehalfTo @{remove = "$user" }
}
} #function Remove-SharedMailbox```
uj5u.com熱心網友回復:
繼續我的評論:
function Remove-SharedMailbox {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]$address,
[Parameter(Mandatory = $true)]
[string[]]$user
)
foreach ($mailbox in $address)
{
foreach ($account in $user)
{
Remove-MailboxPermission `
-Identity $mailbox `
-AccessRights FullAccess `
-Confirm:$false `
-User $account
Remove-RecipientPermission `
-Identity $mailbox `
-AccessRights SendAs `
-Confirm:$false `
-Trustee $account
Set-Mailbox $mailbox -GrantSendOnBehalfTo @{remove = $account }
}
}
}
它最終與您已經在嵌套回圈中使用的邏輯相同。只是通過強制轉換來接受一個字串$user陣列。嵌套回圈遍歷使用傳遞給它的用戶。[string[]]$account
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/435594.html
上一篇:在powershell中解釋字典的Python字串的最佳方法是什么?
下一篇:我搜索如何匹配我的最后一個字符
