从AD中提取用户信息

时间:2017-11-03 23:08:07

标签: powershell active-directory

我试图提取一个用户列表(名字和姓氏),他们的电子邮件地址以及他们所在的容器,但不幸的是,它没有提供数据我需要。我可以获得大部分信息,而不是容器名称。

Get-ADUser -SearchBase 'DC=DOMAINNAME,DC=COM' -Filter {(mail -ne "null") -and (Enabled -eq "true")} -Properties emailAddress |
    Select givenName,surName,OU,emailAddress |
    Format-Table -AutoSize |
    Out-File 'C:\Users\username\Desktop\Lists\Users_List.txt'

2 个答案:

答案 0 :(得分:2)

您正在寻找属性DistinguishedName,但要获得OU,您必须进行一些格式化。如果您运行Get-ADUser | Get-Member,您会看到没有名为OU的属性。

Get-ADUser `
   -SearchBase 'DC=DOMAINNAME,DC=COM' `
   -Filter {(mail -ne "null") -and (Enabled -eq "true")} `
   -Properties emailAddress `
| Select givenName,surName,@{Name='OU';Expression={$_.DistingishedName.Replace("CN=$($_.Name),","")}},emailAddress `
| Format-Table -AutoSize `
| Out-File 'C:\Users\username\Desktop\Lists\Users_List.txt'

关于Understanding PowerShell Custom Properties with the Select-Object cmdlet的文章

答案 1 :(得分:0)

我会将您的邮件过滤器更改为$ false和$ true。我没有安装AD模块的计算机来测试我的答案,否则我会提供更多。

相关问题