我已经在 Google 上搜索并创建了两个脚本。(1),(2)
(1)第一个是导出名为“ap.cz”的共享邮箱的“完全访问权限”
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”的共享邮箱的“发送为”
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 是我组织中的数字。
但是导出到 csv 时我需要获取display name/full name
而不是“ ”。User logon name
我不是 Exchange 管理员,也不精通 Exchange/powershell,但我正在检查/支持整体 IT 基础设施,当经理要求提供姓名列表、对某个邮箱进行“发送”或“完全访问”时,我必须使用上述脚本将其导出并重新转换"user logon name"
为display name
手动。
有人能建议如何将两个脚本都改为显示"full name/display name"
而不是吗login name
?我试过谷歌,但没有成功。
答案1
$用户.用户.原始身份将消除类型转换和更多行...
“完全访问”列表
$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
}
答案2
最后,我得到了编程朋友的帮助(他对 AD 对象一无所知),最终得到了以下解决方案。这可能不是理想的解决方案,但两者都有效,可以达到目的!!希望分享解决方案,以便有人可以受益或可以提出更好的解决方案。
(1)第一个是导出名为“ap.cz”的共享邮箱的“完全访问权限”
$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”的共享邮箱的“发送为”
$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,并将输出保存到输出文件 c:\araa.csv
如何导出到 csv
script2.ps1 | out-file c:\araa.csv
答案3
Powershell 还有一种方法,
$gadu=get-aduser username -properties *
$gadu.Displayname
将输出保存到 var,然后将我们想要查看的字段的名称添加到 var 的末尾,将 $gadu var 视为表格,虽然不像上面的格式那么花哨,但仍然很方便。get-aduser 输出的字段可能很有趣,所以我-properties *
99% 的时间都使用它。