简体   繁体   English

Powershell 活动目录查询

[英]Powershell Active Directory Query

New to using Powershell, so I apologize for any noobness that I show.刚开始使用 Powershell,所以对于我表现出的任何菜鸟,我深表歉意。

I'm trying to extract user names, active status, Expiration Dates and Titles from Active Directory.我正在尝试从 Active Directory 中提取用户名、活动状态、到期日期和标题。

My Powershell command is:我的 Powershell 命令是:

Get-ADUser -Filter * -SearchBase "DC=XXX,DC=XXXX" |
    Select-Object Name, GivenName, Surname, SamAccountName, DistinguishedName, enabled, Title, AccountExpirationDate |
    Export-Csv -Path c:\users\myname\ADUsersWithExpirationDate.csv

The query runs successfully, but does not ever show a Title or Expiration Date even though some user accounts have either or both values in AD.查询成功运行,但从未显示标题或到期日期,即使某些用户帐户在 AD 中有一个或两个值。 Also status (Enabled) does not always populate: the returned values are True, False, or null.此外,状态(启用)并不总是填充:返回值为 True、False 或 null。 All of the Nulls (that I've checked) are active user accounts, but appear to be in non-standard OU's (Admins for example).所有 Null(我已经检查过)都是活动用户帐户,但似乎在非标准 OU 中(例如管理员)。

Any insight or recommendations are very welcome.非常欢迎任何见解或建议。

Thanks in advance.提前致谢。

By default the AD cmdlets don't return all the attributes.默认情况下,AD cmdlet 不会返回所有属性。 You need to use the -Properties parameter to add the AccountExpirationDate and Title attributes to the query.您需要使用-Properties参数将 AccountExpirationDate 和 Title 属性添加到查询中。 Your command should look something like:您的命令应类似于:

Get-ADUser -Filter * -SearchBase "DC=XXX,DC=XXXX" -Properties 'Title','AccountExpirationDate' | 
Select-Object Name, GivenName, Surname, SamAccountName, DistinguishedName, enabled, Title, AccountExpirationDate | 
Export-Csv -Path c:\users\myname\ADUsersWithExpirationDate.csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM