显示用户有权访问的所有邮箱日历(Display all mailbox calendars whic

2019-09-30 20:55发布

我想找出所有用户目前可以访问日历。 我找遍了互联网和最接近的答案我是这样的:

(get-mailbox) | foreach{Get-Mailboxfolderpermission (($_.PrimarySmtpAddress)+":\calendar") -user happyboy -ErrorAction SilentlyContinue} |select identity, user, accessrights

但是,显示并没有真正表现出实际的身份是实际的邮箱这happyboy(上图)可以访问。 该显示器是这样的:

Identity    User        AccessRights    
--------    ----        ------------    
HappyBoy    HappyBoy   {Reviewer}      
HappyBoy    HappyBoy   {LimitedDetails}
HappyBoy    HappyBoy   {Editor}        
HappyBoy    HappyBoy   {Editor}        
HappyBoy    HappyBoy   {Owner}         
HappyBoy    HappyBoy   {Editor} 

我期待这样的事情:

Identity    User        AccessRights    
--------    ----        ------------    
FunnyMan    HappyBoy   {Reviewer}      
PrettyGirl  HappyBoy   {LimitedDetails}
BadBoy      HappyBoy   {Editor}        
LuckyBoy    HappyBoy   {Editor}        
SadGirl     HappyBoy   {Owner}         
LovelyGirl  HappyBoy   {Editor} 

我们可以通过修改脚本来实现这一目标?

Answer 1:

你一个衬垫格式稍有更具可读性:

(Get-Mailbox) | ForEach-Object {
    Get-Mailboxfolderpermission (($_.PrimarySmtpAddress)+":\calendar") `
        -User happyboy -ErrorAction SilentlyContinue
    } | Select-Object Identity, User, Accessrights

应该明确的是,终端管件( Select-Object )接收器的输出Get-Mailboxfolderpermission cmdlet时,将Get-Mailbox输出不再直接访问。

这(未经测试)脚本使用$邮箱变量来存储当前迭代的邮箱。

## Q:\Test\2018\08\14\SO_51836373.ps1

ForEach ($mailbox in (Get-Mailbox)){
    Get-Mailboxfolderpermission (($mailbox.PrimarySmtpAddress)+":\calendar") `
        -User happyboy -ErrorAction SilentlyContinue | ForEach-Object {
        [PSCustomObject]@{
            Identity     = $mailbox.Identity
            User         = $_.User
            AccessRights = $_.Accessrights
        }
    }
}

另一种方法更像你的模板存储在邮箱标识,并插入一个计算性能到选择-对象。 (还未经测试)

(Get-Mailbox) | ForEach-Object {
    $Identity = $_.Identity
    Get-Mailboxfolderpermission (($_.PrimarySmtpAddress)+":\calendar") `
        -User happyboy -ErrorAction SilentlyContinue
    } | Select-Object @{n='Identity';e={$Identity}}, User, Accessrights


文章来源: Display all mailbox calendars which a user has access to