Get-MailboxFolderPermission - foreach循环

时间:2018-01-30 07:54:54

标签: powershell for-loop

我正在尝试输出所有AD用户的日历和联系人权限。我尝试添加-or运算符,但根据错误屏幕截图,它不起作用。我不确定Get-MailboxFolderPermission是否可以使用多个参数。

此脚本无法运行

$OU = OrganizationalUnit "OU=users,OU=test.com,OU=PIPE,OU=Hosting,DC=options,DC=com"

Get-Mailbox -OrganizationalUnit $OU -Filter * |
    select -Expand alias |
    Where-Object {Get-MailboxFolderPermission -Identity $($_ + ':\Calendar') -or $($_ + ':\Contacts')} |
    select Identity, FolderName, User, @{name="AccessRights";expression={[string]::Join(",",@($_.accessrights))}}, IsValid |
    Sort-Object Identity |
    Export-Csv C:\temp\calendarpemstest2.csv 

enter image description here

此脚本可以正常运行获取日历权限

$OU = OrganizationalUnit "OU=users,OU=test.com,OU=PIPE,OU=Hosting,DC=options,DC=com"

Get-Mailbox -OrganizationalUnit $OU -Filter * |
    select -Expand alias |
    ForEach-Object {Get-MailboxFolderPermission -Identity $($_ + ':\Calendar')} |
    select Identity, FolderName, User, @{name="AccessRights";expression={[string]::Join(",",@($_.accessrights)) }}, IsValid |
    Sort-Object Identity |
    Export-Csv C:\temp\calendarpemstest2.csv

1 个答案:

答案 0 :(得分:1)

Powershell尝试解析UPDATE dbo.table SET row1 =( CASE row1 WHEN 'ark-PAR' THEN 'ark-paw' WHEN 'vim-PAR' THEN 'vim-paw' WHEN 'ark-BAR' THEN 'ark-pag' WHEN 'vim-BAR' THEN 'vim-pag' END) 的{​​{1}}参数,但Get-MailboxFolderPermission没有-or参数。

解决此问题的一种方法是将相同的别名对象管道两次(一次用于Get-MailboxFolderPermission,一次用于-or)。

Calendar