首页 > 解决方案 > 如何列出特定计算机上的登录?

问题描述

我必须编写一个简单的脚本,列出在特定 OU 中的每台计算机上登录的所有用户。

我已经尝试过这个函数Get-UserLogon -OU '[distinguished name]'(见这里),但它没有返回任何标准输出。

有什么选择吗?

标签: powershellactive-directoryorganizational-unit

解决方案


您是否尝试过为您的用户提供上次登录时间和日期:

Get-ADUser -Filter * -SearchBase "ou=users,dc=contoso,dc=local" -ResultPageSize 0 -Prop CN,lastLogonTimestamp | Select CN,@{n="lastLogonDate";e={[datetime]::FromFileTime($_.lastLogonTimestamp)}} | Export-CSV -NoType last.csv

参考:https ://expert-advice.org/active-directory/powershell-script-to-get-lastlogon-timestamp-for-specific-ou-and-export-to-csv-file/


推荐阅读