PowerShell Active Directory查询

发布于 2025-02-09 18:48:05 字数 545 浏览 2 评论 0原文

使用PowerShell的新手,所以对于我所展示的任何杂物,我深表歉意。

我正在尝试从Active Directory提取用户名,活动状态,到期日期和标题。

我的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

查询成功运行,但即使某些用户帐户在AD中都有或两个值,也从未显示标题或到期日期。同样,状态(启用)并不总是填充:返回的值是真实的,false或null的。所有的null(我已经检查过的)都是活动用户帐户,但似乎在非标准OU(例如Admins)中。

任何洞察力或建议都非常欢迎。

提前致谢。

New to using Powershell, so I apologize for any noobness that I show.

I'm trying to extract user names, active status, Expiration Dates and Titles from Active Directory.

My Powershell command is:

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. Also status (Enabled) does not always populate: the returned values are True, False, or 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).

Any insight or recommendations are very welcome.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2025-02-16 18:48:05

默认情况下,AD CMDLET不会返回所有属性。您需要使用-properties参数将accountExpirationDate和标题属性添加到查询中。您的命令应该看起来像:

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

By default the AD cmdlets don't return all the attributes. You need to use the -Properties parameter to add the AccountExpirationDate and Title attributes to the query. 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文