
Ich weiß nicht, wie ich SAMAccounts (AD-Benutzernamen) zu den Ergebnissen hinzufügen kann. Kann mir jemand helfen?
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
Antwort1
Sie haben dies gepostet aufStapelaustauschund hier war auch meine Antwort für Sie und für diejenigen, die nicht direkt zum Link springen möchten.
Sie können SamAccountName mit dem Cmdlet Get-Mailbox abrufen.
((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
...
#>
Es wird einfach nicht weitergegeben, wie hier angegeben ... Beispiel:
(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
...
#>
Versuchen Sie es also folgendermaßen ...
(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
...
#>
Update zum OP
Was Ihren Kommentar betrifft …
Hallo, dieser Fehler tritt auf: Invoke-Command: Der Parameter „Filter“ kann nicht an das Ziel gebunden werden. Ausnahmeeinstellung „Filter“: „Ungültige Filtersyntax. Eine Beschreibung der Filterparametersyntax finden Sie in der Befehlshilfe. „*“ an Position 1.“
… wie aus meinem Kommentar vor diesem Update hervorgeht.
Das Beispiel besteht ausschließlich aus normaler PowerShell und sollte lokal oder remote funktionieren (sofern Sie PSRemoting richtig eingerichtet haben, lokaler Administrator auf der Remote-Box sind und dies als dieser Administrator ausführen).
Wenn Sie dies ausführen …
Invoke-Command -ComputerName ex01 -ScriptBlock {Get-Mailbox -Filter '*' -ResultSize Unlimited}
oder dieses...
Invoke-Command -ComputerName ex01 -ScriptBlock {(Get-Mailbox -Filter '*' -ResultSize Unlimited).SamAccountName}
Oder dieses...
Invoke-Command -ComputerName ex01 -ScriptBlock {Get-Mailbox -Filter '*' -ResultSize Unlimited | Select-Object -Property SamAccountName}
... was passiert von selbst in Ihrer Umgebung während einer PSRemoting-Sitzung?
Wenn Sie Ihre PSRemoting-Sitzung wie folgt durchführen ...
$ExpSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' -ConnectionUri ("http://$Ex01Fqdn/PowerShell") -Authentication Kerberos -Credential $Creds
Import-PSSession $ExpSession
Dann brauchen Sie den Invoke-Befehl überhaupt nicht, da die Cmdlets bereits an Ihre Workstation weitergeleitet werden. Führen Sie den Code einfach so aus, wie er ist.
Beispiel – Implizite PSRemoting-Sitzung unter Nutzung von -Prefix
Dieses Präfix ist nicht unbedingt erforderlich, es ist nur eine Gewohnheit, die ich für alle meine impliziten Remotesitzungen standardmäßig verwende. Das Präfix wird empfohlen, wenn Sie beispielsweise sowohl Exchange Online-Cmdlets als auch die Exchange On-Prem-Cmdlets auf derselben Box verwenden, um Verwirrung und Fehler zu vermeiden.):
($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.