积极答复者
导出AD用户信息

问题
答案
-
您好,
可以把时间的过滤条件去掉
$file = "C:\temp\info.csv" Get-ADUser -Filter * -Properties DisplayName,EmployeeID,mail,mailnickname,LastLogonDate | Select-Object -Property DisplayName,EmployeeID,mail,mailnickname,Enabled,LastLogonDate | Export-Csv -NoTypeInformation -Path $file -Encoding UTF8
如您还有其他疑问,请随时与我们联系。如果回答是有帮助的,请将其标记为答案,可以帮助其他社区成员快速找到有用的答复。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已标记为答案 dnake668 2021年7月13日 9:21
全部回复
-
您好,
要获取AD用户可以使用Get-ADUser这个命令。不清楚上面说的邮箱类型是不是指的msExchRecipientTypeDetails。如果是的话,需要注意RecipientTypeDetails是以一个整数的形式保存的。不是的话可以自行将msExchRecipientTypeDetails换成其他的属性。
$user = "abc" $file = "C:\temp\info.txt" Get-ADUser -Identity $user -Properties DisplayName,msExchRecipientTypeDetails,mail,mailnickname,homeMDB,enabled,lastlogondate | Select-Object DisplayName,msExchRecipientTypeDetails,mail,mailnickname,homeMDB, @{n="Group";e={(Get-ADPrincipalGroupMembership -Identity $user).DistinguishedName}},enabled,lastlogondate | Export-Csv -NoTypeInformation -Path $file
关于msExchRecipientTypeDetails属性可以参考这个链接
https://answers.microsoft.com/en-us/msoffice/forum/all/recipient-type-values/7c2620e5-9870-48ba-b5c2-7772c739c651
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已编辑 Ian Xue 2021年7月12日 8:22
- 已建议为答案 Bryan丶Song 2021年7月12日 9:39
-
您好,
这个$user是用户名,可以将abc替换成实际的用户名称。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. -
您好,
要导出域中所有用户的话可以这样
$file = "C:\temp\info.csv" Get-ADUser -Filter * -Properties DisplayName,msExchRecipientTypeDetails,mail,mailnickname,homeMDB,enabled,lastlogondate | Select-Object DisplayName,msExchRecipientTypeDetails,mail,mailnickname,homeMDB, @{n="Group";e={(Get-ADPrincipalGroupMembership -Identity $_.name).DistinguishedName}},enabled,lastlogondate | Export-Csv -NoTypeInformation -Path $file
如您还有其他疑问,请随时与我们联系。如果回答是有帮助的,请将其标记为答案,可以帮助其他社区成员快速找到有用的答复。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已编辑 Ian Xue 2021年7月13日 1:51
-
您好,
不是很确定您的环境里工号是用的什么属性,EmployeeID还是EmployeeNumber?这个可以自行到ADUC中用户的属性页去确认下。假设用的是EmployeeID,那么可以Get-ADUser查看下面这些属性。
关于只导出最近三个月记录,是要只导出最后登录时间是在三个月以内的用户?是的话可以试下这个
$file = "C:\temp\info.csv" $date=(Get-Date).AddDays(-90) Get-ADUser -Filter {LastLogonDate -gt $date} -Properties DisplayName,EmployeeID,mail,mailnickname,LastLogonDate | Select-Object -Property DisplayName,EmployeeID,mail,mailnickname,Enabled,LastLogonDate | Export-Csv -NoTypeInformation -Path $file
如您还有其他疑问,请随时与我们联系。如果回答是有帮助的,请将其标记为答案,可以帮助其他社区成员快速找到有用的答复。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
- 已编辑 Ian Xue 2021年7月13日 5:01
-
您好,
有中文的话可以编码改为UTF8。
$file = "C:\temp\info.csv" $date=(Get-Date).AddDays(-90) Get-ADUser -Filter {LastLogonDate -gt $date} -Properties DisplayName,EmployeeID,mail,mailnickname,LastLogonDate | Select-Object -Property DisplayName,EmployeeID,mail,mailnickname,Enabled,LastLogonDate | Export-Csv -NoTypeInformation -Path $file -Encoding UTF8
关于登陆时间,net user查询的是LastLogon属性,而上面LastLogonDate实际查询的是LastLogonTimestamp属性。看您上面的描述,域中可能有多个DC。LastLogonTimestamp属性是会在DC之间复制的,而LastLogon属性是不会在DC间复制的,用户登陆时修改的只有当前提供登录验证的DC,因此出现获取的LastLogon不同于LastLogonTimestamp。
关于更加具体的一些说明,可以参考
https://social.technet.microsoft.com/wiki/contents/articles/22461.understanding-the-ad-account-attributes-lastlogon-lastlogontimestamp-and-lastlogondate.aspx
如您还有其他疑问,请随时与我们联系。如果回答是有帮助的,请将其标记为答案,可以帮助其他社区成员快速找到有用的答复。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. -
您好,
可以把时间的过滤条件去掉
$file = "C:\temp\info.csv" Get-ADUser -Filter * -Properties DisplayName,EmployeeID,mail,mailnickname,LastLogonDate | Select-Object -Property DisplayName,EmployeeID,mail,mailnickname,Enabled,LastLogonDate | Export-Csv -NoTypeInformation -Path $file -Encoding UTF8
如您还有其他疑问,请随时与我们联系。如果回答是有帮助的,请将其标记为答案,可以帮助其他社区成员快速找到有用的答复。
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已标记为答案 dnake668 2021年7月13日 9:21
-
您好
如果要查看属性,需要进入“Active Directory 用户和计算机”,在“查看”菜单上,选中“高级功能”,然后在需要查看的用户上右键点击”属性“,然后选择“属性编辑器“选项卡。
看您上面的描述,所说的这个工号可能是SamAccountName,可以看一下这个的结果
$file = "C:\temp\info.csv" Get-ADUser -Filter * -Properties DisplayName,mail,mailnickname,LastLogonDate | Select-Object -Property DisplayName,SamAccountName,mail,mailnickname,Enabled,LastLogonDate | Export-Csv -NoTypeInformation -Path $file -Encoding UTF8
祝好
Ian Xue
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已编辑 Ian Xue 2021年7月14日 6:28