Retrieve users with same “City” through Get-ADuser

社会主义新天地 提交于 2019-12-13 05:48:13

问题


Is there a way by which I can retrieve a list of AD's only belonging to a particular "City"?

Because, there is a property in SET-ADuser -city, so there must be a way for the reverse also!


回答1:


The "City" field is mapped to an LDAP attribute called "Locality-Name". The LDAP Display Name for said property is l (that's a lowercase L):

Get-ADUser "mwood" -Properties l | Select-Object Name,@{Name="City";Expression={$_.l}}

It also seems that Get-ADUser is able to do the translation itself, so you can use a filter like:

Get-ADUser -Filter "City -eq 'CityName'"

You could also use an LDAP filter:

Get-ADUser -LDAPFilter "(&(l=CityName)(!(HomeDirectory=*)))"



回答2:


Get-ADUser -Filter "*" -Properties City | Where-Object {$_.City -eq "Dublin"}

or

Get-ADUser -Filter "City -eq 'Dublin'"

let me know if either of these work for you



来源:https://stackoverflow.com/questions/31872720/retrieve-users-with-same-city-through-get-aduser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!