powershell - 从SAMaccountname获取用户的电子邮件地址

标签 powershell active-directory

我是PowerShell的新手,但实际上我需要一个脚本,因此我开始将自己读入其中,并找到了Powershell。

我有一个用户名列表,例如:

  • xyxz
  • 域名\ xyxz.xyxc

  • 该脚本应从我的用户列表中搜索所有samaccountname,并为我提供每个samaccountname的电子邮件地址。

    获取内容C:\ Users \ xxxxx \ Desktop \ Users.txt | forEach {
    Get-ADUser“我不知道如何指定用户名”选择邮件| Export-Csv output.csv
    }

    这是我正在编写的脚本,但是我不知道如何完成它以使其正常工作。我知道这做得不好,但是我不想自己做些事情在这里写一些文字。

    最佳答案

    你有点亲密

    Get-Content C:\Users\xxxxx\Desktop\Users.txt | forEach { Get-ADUser $_ -properties EmailAddress} | select -ExpandProperty EmailAddress | Out-File output.csv 
    

    应该可以解决这个问题(如果您的txt文件包含samid,并且每行只有一个)。

    您可以使用$_访问管道内部的对象。另外,要通过select获得属性的String值,还必须使用-ExpandProperty

    在这种情况下,还必须特别选择属性(EmailAddress),因为默认情况下仅报告有限的一组属性以减少工作量(这是通过指定-properties参数来完成的。

    关于powershell - 从SAMaccountname获取用户的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27123416/

    相关文章:

    powershell - 在powershell中如何模拟按住shift键?

    winforms - 从 powershell 调用 FolderBrowserDialog

    c# - 奇怪的 COM 互操作异常 0x80005000 使用 System.DirectoryServices.AccountManagement 库

    active-directory - Active Directory 真的符合 LDAP 标准吗?

    authentication - Windows Azure ACS 和/或 Active Directory (WAAD)

    powershell - 尝试为 Active Directory 运行 PowerShell 脚本时出现错误解析错误

    powershell - 带有空白行的PowerShell “cat <file>”将空格视为空格

    powershell - 如何使用 PowerShell 检查特定服务是否在远程计算机上运行

    arrays - Invoke-WebRequest : Cannot bind parameter 'Uri' . 无法转换“@{

    vbscript - Active Directory VBS搜索脚本的第1行中的错误 'Expected end of statement'