如何在导出“send as”和“full”权限时获取AD用户的“显示名称”而不是login名(domain \ userid)?

我已经search并创build了两个脚本。 (1),(2)

(1)首先导出一个名为“ap.cz”的共享邮箱的“Full Access”

Get-Mailbox ap.cz | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | Export-Csv \\myserver\c$\fulla.csv –NoTypeInformation 

(2)第二个是导出名为“ap.cz”的共享邮箱的“Send As”

 Get-Mailbox ap.cz | Get-ADPermission | where { ($_.ExtendedRights -like “*Send-As*”) -and ($_.IsInherited -eq $false) -and -not ($_.User -like “NT AUTHORITY\SELF”) } | Select Identity, User, Deny | Export-CSV \\myserver\c$\sendass.csv 

这两个脚本工作正常。

(1)的输出与此类似

在这里输入图像说明

(2)的输出与此类似

在这里输入图像说明

但是,对于这两种情况,我都以“ User logon name ”格式( domain\userid ),其中userid是我的组织中的一个数字。

但我需要display name/full name而不是“ User logon name ”,而导出到csv ..

我不是交换pipe理员,也不是交换/ PowerShell精通,但我正在检查/支持整体的IT基础设施,当一个经理要求一个名单的名单,“发送为”或“完全访问”邮箱,我必须使用上述脚本导出它,并重新转换"user logon name"手动display name

有人可以请教如何更改这两个脚本显示"full name/display name"而不是login name ? 我曾试过googlin,但没有运气..

$ users.user.rawidentity将消除types转换和几行…

“完全访问”列表

 $users=Get-Mailbox ap.cz | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} $ss=$users.user.rawidentity | Where-Object {$_ -notlike "s-1*"} foreach ($item in $ss){ $b = $item.Split("\") $c=$b.Split("}")[1] Get-ADUser -identity $c -properties DisplayName | select DisplayName } 

“发送为”列表

 $users=Get-Mailbox ap.cz | Get-ADPermission | where { ($_.ExtendedRights -like “*Send-As*”) -and ($_.IsInherited -eq $false) -and -not ($_.User -like “NT AUTHORITY\SELF”) } | Select User $ss=$users.user.rawidentity | Where-Object {$_ -notlike "s-1*"} foreach ($item in $ss){ $b = $item.Split("\") $c=$b.Split("}")[1] Get-ADUser -identity $c -properties DisplayName | select DisplayName } 

最后,我和我的编程朋友(谁对AD对象一无所知)得到了帮助,并以下面的解决scheme结束了。这可能不是理想的解决scheme,但两者都可以节省目的! 希望分享这个解决scheme,所以有人可以受益,或者可以提出更好的解决scheme。

(1)首先导出一个名为“ap.cz”的共享邮箱的“Full Access”

  $users=Get-Mailbox ap.cz | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select User $num=$users.length for ($i=0; $i -lt $num; $i++) { Try { $item=$users[$i] $itemcast=[string]$item $b = $itemcast.Split("\")[1] $c=$b.Split("}")[0] Get-ADUser -identity $c -properties DisplayName | select DisplayName } catch { $error="error" } } 

(2)第二个是导出名为“ap.cz”的共享邮箱的“Send As”

  $users=Get-Mailbox ap.cz | Get-ADPermission | where { ($_.ExtendedRights -like “*Send-As*”) -and ($_.IsInherited -eq $false) -and -not ($_.User -like “NT AUTHORITY\SELF”) } | Select User $num=$users.length for($i=0; $i -lt $num; $i++) { Try { $item=$users[$i] $itemcast=[string]$item $b = $itemcast.Split("\")[1] $c=$b.Split("}")[0] Get-ADUser -identity $c -properties DisplayName | select DisplayName } catch { $error="error" } } 

这两个脚本都保存为script1.ps1和script2.ps1,输出保存为out-file c:\ araa.csv

如何导出到csv

  script2.ps1 | out-file c:\araa.csv 

Powershell更多的方式,

 $gadu=get-aduser username -properties * $gadu.Displayname 

将输出保存到一个var,然后将我们想要查看的字段的名称添加到var的末尾,将$ gadu var作为表格,而不像上面那样格式化,但仍然方便。 get-aduser对于输出的字段可能很有趣,所以我使用-properties * 99%的时间。