使用powershell创建过期广告用户的csv

使用powershell创建过期广告用户的csv,powershell,active-directory,Powershell,Active Directory,我已经在下面创建了powershell脚本。它工作正常,但我想让它返回给用户的经理。似乎该对象返回了,但搜索帐户没有这样做。有人能帮忙吗?谢谢 $UserList = Search-ADAccount -AccountExpiring -UsersOnly -TimeSpan 07.00:00:00 | Select-Object name, AccountExpirationDate, LastLogonDate, UserPrincipalName $R

我已经在下面创建了powershell脚本。它工作正常,但我想让它返回给用户的经理。似乎该对象返回了,但搜索帐户没有这样做。有人能帮忙吗?谢谢

$UserList = Search-ADAccount -AccountExpiring -UsersOnly -TimeSpan 07.00:00:00 | Select-Object name,                   AccountExpirationDate, LastLogonDate, UserPrincipalName 
$ReportName = "C:\Users\administrator\desktop\ExpiringUsers-7DayReport.csv" 
$UserList | Export-CSV $ReportName

Search-ADAccount
可能不会直接为您提供所需信息,但通过一个简单的管道进入
Get-AdUser
将为您提供其余信息

$UserList = Search-ADAccount -AccountExpiring -UsersOnly -TimeSpan 07.00:00:00 | 
     Get-ADUser -Properties Manager,AccountExpirationDate,LastLogonDate | 
     Select-Object Name,Manager,AccountExpirationDate,LastLogonDate,UserPrincipalName
$ReportName = "C:\Users\administrator\desktop\ExpiringUsers-7DayReport.csv" 
$UserList | Export-CSV $ReportName
您正在查找的一些属性在
Get AdUser
的属性中不是标准属性,因此我们需要确保使用
-properties
收集这些属性

根据评论更新

如果您想要的是经理的名字而不是dn,那么您需要将其提取出来,就像我们对
搜索账户的结果所做的那样。一种方法是更改
选择
行,如下所示:

Select-Object Name,AccountExpirationDate,LastLogonDate,UserPrincipalName,@{Name="Manager Name";Expression={$_.Manager | Get-Aduser | Select-Object -ExpandProperty Name}}

创建一个名为
Manager Name
的计算属性(无法使用
Manager
,因为已经存在具有该名称的属性)。将管理器导入
getaduser
并提取name属性

谢谢你。是否可以返回经理的姓名而不是可分辨名称?