Powershell - 获取给定OU的用户属性

时间:2014-11-12 16:32:20

标签: powershell active-directory

我需要获取给定OU中所有用户的用户信息(帐户,电子邮件,姓名,位置,OU)。我试过跟随,但它没有给我任何东西。知道为什么吗?

PS C:\> Get-ADUser -Filter {OU -like "northwest-academy"}
PS C:\> Get-ADUser -Filter {OU -like "northwest-academy"} -Properties * | select e
mailaddress
PS C:\> Get-ADUser -Filter {OU -like "northwest-academy} -Properties * | select e
mailaddress.emailaddress
PS C:\> $test = Get-ADUser -Filter {OU -like "northwest-academy} -Properties * |
select emailaddress.emailaddress
PS C:\> write-host $test

PS C:\> $test = Get-ADUser -Filter {EmailAddress -like "smith"} -Properties * |
select emailaddress
PS C:\> write-host $test

PS C:\> $test = Get-ADUser -Filter {OU -like "northwest-academy} -Properties Emai
lAddress
PS C:\> $test.EmailAddress
PS C:\>

2 个答案:

答案 0 :(得分:0)

OU不是LDAP用户帐户的属性。请尝试Get-ADUser -Identity '$YourUserName' -Properties *获取有效属性列表。

过滤器{EmailAddress -like "smith"}不包含通配符,因此不包含部分匹配。试试{EmailAddress -like "*smith*"}

答案 1 :(得分:0)

这个脚本有效。但是我注意到OU排队区分大小写或其他什么。所以首先我必须通过从该OU中获取用户来获得该特殊组的正确ou。例如,

PS C:\> $test = Get-ADUser -Filter {EmailAddress -like "*Stanley*"} -Properties EmailAddress
PS C:\> write-host $test
PS C:\> $OU = "ou=specialusers,ou=users,dc=mydomain,dc=com"



Get-ADUser -searchbase $OU -filter * -Properties Department | Select-Object name, department > c:\temp\myfile.csv