Active Directory -如何从otherpager属性数组中检索信息



一位同事在活动目录的otherPager属性中放入了一条信息。我必须找回这个信息。我正在使用这个代码

Import-Module ActiveDirectory
Get-ADUSER -Filter * -properties otherPager | Select-Object -Property Name, Surname, UserPrincipalName, {$_.otherPager}[0]  | Sort-Object Name | Export-Csv -Path "\srv-qlikeDatawarehouseautres sourcesGestion des droitsActive_directory_users.csv" -Encoding Default -NoTypeInformation

otherPager属性输出为Microsoft.ActiveDirectory.Management.ADPropertyValueCollection。这不是我所期望的。

我搜索了其他互联网,发现otherPager属性包含在一个数组中,但没有关于如何访问其元素的信息。实际上我只需要这个数组的第一个元素。

你能帮忙吗?

更新代码的第一个问题是默认情况下也不返回EmailAddress,您需要在参数-Properties中指定它。

我认为第二个问题是您为生成的CSV文件设置输出路径的位置。如果路径设置在服务器的E驱动器上,则需要在此处添加一个美元符号:\srv-qlike$Datawarehouseautres sourcesGestion des droitsActive_directory_users.csv

Import-Module ActiveDirectory
$outputFile = '\srv-qlike$Datawarehouseautres sourcesGestion des droitsActive_directory_users.csv'
Get-ADUser -Filter * -Properties otherPager, EmailAddress | 
Select-Object Name, Surname, UserPrincipalName, EmailAddress,
@{Name='test'; Expression = {@($_.otherPager)[0]}} |
Sort-Object Name | 
Export-Csv -Path $outputFile -Encoding Default -NoTypeInformation

最新更新