基本上我在这里想要实现的是一个带有 4 列/列表的输出(在这种情况下我作为文本导出)Get-MailboxPermission 给了我一个身份、用户、访问权限的属性,但它没有给我一个“经理”的财产。我需要确定该特定用户向何处报告。所以,我尝试了 PSCustomObject 并希望我可以将结果放入一个数组中。请参阅下面的脚本
$GETMAILBOXPERM = Get-Content C:\Users\Account\Desktop\MailboxUsers\MAILBOXESUSERS.txt | ForEach-Object {Get-MailboxPermission $_ |
where {
($_.User -notlike ‘*NT AUTHORITY*’) -and
($_.User -notlike ‘*S-1-5-21-*’) -and
($_.User -notlike ‘*NAMPRD08*’) -and
($_.User -notlike ‘*PRDTSB01*’) -and
($_.User -notlike ‘*0365Admin*’) -and
($_.User -notlike ‘*Discovery Management*’) -and
($_.User -notlike ‘*NAMPR08A005*’) -and
($_.User -notlike ‘*NT AUTHORITY*’)
}
}
$Results = foreach( $Mailbox in (get-content C:\Users\Account\Desktop\MailboxUsers\MAILBOXESUSERS.txt))
{
$Users = Get-User $Mailbox
if ($Users){
foreach ($User in $Users){
[pscustomobject]@{
DisplayName = $User.name
Account = $GETMAILBOXPERM.user
Manager = $User.manager
Access = $GETMAILBOXPERM.accessrights
}
}
}
}
$Results | Format-List -Property DisplayName, Account, Manager, Access | Out-File C:\Users\Account\Desktop\MailboxUsers\mailbox4.txt
这是文本文件中的输出。我得到了正确的 DisplayName 和 Manager,但 Account 和 Access 似乎没有从文本文件中循环。
显示名称:MAILBOX1
帐户:{user1@domain.ca, user2@domain.ca, user3@domain.ca, user4@domain.ca...}
经理 : MANAGER1
访问:{FullAccess、FullAccess、FullAccess、FullAccess...}
显示名称:MAILBOX2
帐户:{user1@domain.ca, user2@domain.ca, user3@domain.ca, user4@domain.ca...}
经理:MANAGER2
访问:{FullAccess、FullAccess、FullAccess、FullAccess...}