You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Active Directory的otherPager数组属性提取首个元素?

解决Active Directory otherPager数组属性导出CSV问题

你的问题出在计算属性的写法上,{$_.otherPager}[0] 是把整个脚本块对象取索引0,而非在脚本块内部访问数组的第一个元素。要正确获取otherPager的第一个元素,需在脚本块内完成数组索引操作,同时给计算属性指定友好列名,避免CSV出现奇怪的列标题。

修正后的代码如下:

Import-Module ActiveDirectory
Get-ADUSER -Filter * -Properties otherPager | 
    Select-Object -Property Name, Surname, UserPrincipalName, 
        @{Name='OtherPagerFirstItem'; Expression={$_.otherPager[0]}} | 
    Sort-Object Name | 
    Export-Csv -Path "\\srv-qlik\e\Datawarehouse\autres sources\Gestion des droits\Active_directory_users.csv" -Encoding Default -NoTypeInformation

关键说明:

  • 用@{Name='列名'; Expression={脚本逻辑}}格式定义计算属性,CSV里会显示你指定的列名(示例中为OtherPagerFirstItem)
  • 在Expression脚本块内,通过$_.otherPager[0]直接访问数组第一个元素,确保返回实际属性值而非集合对象
  • 若部分用户的otherPager属性为空,代码会自动返回空值,不会引发报错

内容的提问来源于stack exchange,提问作者Philippe MERLE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 09:42:11