
결과에 SAMAccounts(AD 사용자 이름)를 추가하는 방법이 궁금합니다. 누구든지 도움을 받을 수 있습니까?
Get-Mailbox -ResultSize Unlimited | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select Identity,User,Username,@{Name='Access Rights';Expression= {[string]::join(', ', $_.AccessRights)}} | Export-Csv -NoTypeInformation C:\temp\mailboxpermissions1.csv
답변1
당신이 이 글을 다음 주소에 게시했습니다:스택교환그리고 여기에 있는 당신과 링크로 넘어가지 않으려는 사람들을 위한 내 대답은 다음과 같습니다.
Get-Mailbox cmdlet을 사용하여 SamAccountName을 가져올 수 있습니다.
((Get-Mailbox -Filter '*')[0] | Get-Member).Name
# Results
<#
PS C:\Scripts> ((Get-Mailbox -Filter '*')[0] | Get-Member).Name
...
RoomMailboxAccountEnabled
RulesQuota
SamAccountName
SCLDeleteEnabled
...
#>
Get-Mailbox -Filter '*' | ForEach {$PSItem.SamAccountName}
# Results
<#
Get-Mailbox -Filter '*' | ForEach {$PSItem.SamAccountName}
Administrator
...
#>
여기에 언급된 것처럼 파이프라인으로 전달되지는 않습니다... 예:
(Get-Mailbox -Filter '*' -ResultSize Unlimited).SamAccountName |
ForEach{Get-MailboxPermission -Identity $PSItem} |
Where-Object {
$PSItem -ne 'NT AUTHORITY\SELF' -and
$PSItem.IsInherited -eq $false
} | Select-Object -Property '*'
# Results
<#
AccessRights : {FullAccess, ReadPermission}
Deny : False
InheritanceType : All
User : NT AUTHORITY\SELF
Identity : contoso.com/Users/Administrator
IsInherited : False
IsValid : True
ObjectState : Unchanged
...
#>
그럼 이 방법으로 시도해 보세요...
(Get-Mailbox -Filter '*' -ResultSize Unlimited).SamAccountName |
ForEach{Get-MailboxPermission -Identity $PSItem} |
Where-Object {
$PSItem -ne 'NT AUTHORITY\SELF' -and
$PSItem.IsInherited -eq $false
} | Select-Object -Property Identity,User,
@{Name = 'SamAccountName';Expression = {(Get-ADUser -Identity $($PSitem.Identity -split '/')[-1]).SamAccountName}},
@{Name = 'Access Rights';Expression = {[string]::join(', ', $PSItem.AccessRights)}}
# Results
<#
Identity User SamAccountName Access Rights
-------- ---- -------------- -------------
contoso.com/Users/Administrator NT AUTHORITY\SELF Administrator FullAccess, ReadPermission
...
#>
OP 업데이트
당신의 댓글로는...
안녕하세요. 다음 오류가 발생합니다. Invoke-Command: 'Filter' 매개변수를 대상에 바인딩할 수 없습니다. 예외 설정 "필터": "잘못된 필터 구문. 필터 매개변수 구문에 대한 설명은 명령 도움말을 참조하십시오. 위치 1에 "*"가 있습니다.
... 이 업데이트 이전의 내 의견에서 언급했듯이.
샘플은 모두 원시 일반 PowerShell이며 로컬 또는 원격으로 작동해야 합니다(PSRemoting이 올바르게 설정되어 있고 원격 상자의 로컬 관리자이고 이를 해당 관리자로 실행하는 경우)
이것을 실행하면…
Invoke-Command -ComputerName ex01 -ScriptBlock {Get-Mailbox -Filter '*' -ResultSize Unlimited}
아니면 이거...
Invoke-Command -ComputerName ex01 -ScriptBlock {(Get-Mailbox -Filter '*' -ResultSize Unlimited).SamAccountName}
아니면 이거...
Invoke-Command -ComputerName ex01 -ScriptBlock {Get-Mailbox -Filter '*' -ResultSize Unlimited | Select-Object -Property SamAccountName}
... PSRemoting 세션을 통해 사용자 환경에서 자체적으로 어떤 일이 발생합니까?
PSRemoting 세션을 다음과 같이 수행하는 경우...
$ExpSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' -ConnectionUri ("http://$Ex01Fqdn/PowerShell") -Authentication Kerberos -Credential $Creds
Import-PSSession $ExpSession
그러면 cmdlet이 이미 워크스테이션에 프록시되어 있으므로 Invoke-Command가 전혀 필요하지 않습니다. 코드를 그대로 실행하면 됩니다.
예 - -Prefix를 활용하는 암시적 PSRemoting 세션
이 -접두사는 반드시 필요한 것은 아니며 모든 암시적 원격 세션에 사용하도록 표준화한 습관일 뿐입니다. 혼동과 오류를 피하기 위해 동일한 상자에서 Exchange Online cmdlet과 Exchange 온-프레미스 cmdlet을 모두 사용하는 경우 -prefix를 사용하는 것이 좋습니다.):
($ExpSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' -ConnectionUri ("http://$Ex01Fqdn/PowerShell") -Authentication Default)
<#
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
8 Session8 ex01.contoso... Opened Microsoft.Exchange Available
#>
Import-PSSession $ExpSession -Prefix 'EXP'
<#
WARNING: The names of some imported commands from the module 'tmp_zucxz5zd.0ee' include unapproved verbs that might make them less discoverable. To find the commands wi
th unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0 tmp_zucxz5zd.0ee {Add-EXPADPermission, Add-EXPAvai...
#>
(Get-ExpMailbox -Filter '*' -ResultSize Unlimited).SamAccountName |
ForEach{Get-ExpMailboxPermission -Identity $PSItem} |
Where-Object {
$PSItem -ne 'NT AUTHORITY\SELF' -and
$PSItem.IsInherited -eq $false
} | Select-Object -Property Identity,User,
@{Name = 'SamAccountName';Expression = {(Get-ADUser -Identity $($PSitem.Identity -split '/')[-1]).SamAccountName}},
@{Name = 'Access Rights';Expression = {[string]::join(', ', $PSItem.AccessRights)}}
# The results would be the same as my original response.