简体   繁体   English

Powershell:如何从 OU 中的用户获取特定属性

[英]Powershell: How to get specific properties from users in a OU

I am trying to get some information for an audit.我正在尝试获取一些信息以进行审计。 here's the code that i used but the output is empty except for the name.这是我使用的代码,但除了名称之外 output 是空的。 Can anyone point me in the right direction?谁能指出我正确的方向?

Thanks in advance!提前致谢!

$ou = Get-ADGroup -Identity Administrators -Properties member
$user = Get-ADGroupmember -Identity $ou 
    foreach ($user in $ou){
    Get-ADGroupmember -Identity Administrators | Select-Object name, lastlogondate,passwordlastset
    }

Try this尝试这个

$members = Get-ADGroupMember -Identity Administrators -recursive | select samaccountname

foreach ($user in $members){
Get-ADUser -Identity  $user.samaccountname -Properties name, lastlogondate,passwordlastset| Select-Object name, lastlogondate,passwordlastset
}

By default the properties lastlogondate and passwordlastset are not returned, you have to specify those (or all by using a *) using the -properties argument默认情况下不会返回属性 lastlogondate 和 passwordlastset,您必须使用 -properties 参数指定这些(或全部使用 *)

Get-ADGroupmember -Identity Administrators -properties name,lastlogondate,passwordlastset | Select-Object name, lastlogondate,passwordlastset

or或者

Get-ADGroupmember -Identity Administrators -properties * | Select-Object name, lastlogondate,passwordlastset

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

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