AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 820598
Accepted
user879
user879
Asked: 2016-12-14 22:20:16 +0800 CST2016-12-14 22:20:16 +0800 CST 2016-12-14 22:20:16 +0800 CST

如何在导出“发送为”和“完整”权限时获取 AD 用户的“显示名称”而不是登录名(域\用户 ID)?

  • 772

我用谷歌搜索并创建了两个脚本。(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”的共享邮箱的“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 是我组织中的一个数字。

但是在导出到 csv 时我需要得到display name/full name而不是“ ”。User logon name

我不是交易所管理员或精通交易所/powershell,但我正在检查/支持整体 IT 基础架构,当经理要求提供姓名列表时,对于某个特定的“发送为”或“完全访问”邮箱,我必须使用上述脚本将其导出并手动重新转换"user logon name"。display name

有人可以建议如何将两个脚本更改为显示"full name/display name"而不是login name?我试过谷歌,但没有运气..

scripting exchange powershell active-directory exchange-2013
  • 3 3 个回答
  • 4959 Views

3 个回答

  • Voted
  1. Best Answer
    Aravinda
    2017-09-17T19:53:44+08:002017-09-17T19:53:44+08:00

    $users.user.rawidentity将消除类型转换和几行...

    “完全访问”列表

    $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
    }
    
    • 1
  2. user879
    2017-03-21T00:58:18+08:002017-03-21T00:58:18+08:00

    最后,我得到了我的编程朋友的帮助(谁对 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”的共享邮箱的“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,输出保存到输出文件 c:\araa.csv

    如何导出到 csv

     script2.ps1 | out-file c:\araa.csv
    
    • 0
  3. Johnb85022
    2016-12-16T15:15:38+08:002016-12-16T15:15:38+08:00

    Powershell的另一种方式,

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

    将输出保存到 var 中,然后在 var 的末尾添加我们要查看的文件的名称,将 $gadu var 视为表格,不像上面的格式那么花哨,但仍然很方便。get-aduser 对它输出的字段可能很有趣,所以我-properties *99% 的时间都在使用它。

    • -2

相关问题

  • 知道任何适用于 Windows 的快速可编写脚本的 ftp 客户端吗?[关闭]

  • 如果同一个任务已经在运行,如何防止计划任务运行?

  • 需要从 Batch For 循环中排除特定结果

  • Bash 脚本:要求脚本以 root 身份运行(或使用 sudo)

  • 从命令行删除旧的(非引导)Windows Vista 目录

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve