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

如何通过PowerShell仅导出AD组中指定列的成员数据

解决AD组成员导出指定列的问题

你的问题核心是未明确筛选要导出的属性列——即便在Get-ADUser中指定了-Property,PowerShell仍会返回该cmdlet的默认属性集合,必须通过Select-Object精准提取你需要的三列。

修改后的代码如下:

$groupNames = @("GroupName1", "GroupName2", "GroupName3", "GroupName4")

For ($i=0; $i -lt $groupNames.Length; $i++) {
    $currentGroup = $groupNames[$i]
    $csvPath = "$currentGroup.csv"

    Get-ADGroup $currentGroup -Properties Member | 
        Select-Object -Expand Member | 
        Get-ADUser -Properties name, objectClass, distinguishedName | 
        Select-Object name, objectClass, distinguishedName |  # 新增此行筛选目标列
        Export-CSV -Path $csvPath -NoTypeInformation
}

额外提示

如果AD组内包含非用户对象(如其他组、计算机),Get-ADUser会触发报错,此时可改用Get-ADObject兼容所有对象类型,调整后代码如下:

$groupNames = @("GroupName1", "GroupName2", "GroupName3", "GroupName4")

For ($i=0; $i -lt $groupNames.Length; $i++) {
    $currentGroup = $groupNames[$i]
    $csvPath = "$currentGroup.csv"

    Get-ADGroup $currentGroup -Properties Member | 
        Select-Object -Expand Member | 
        Get-ADObject -Properties name, objectClass, distinguishedName | 
        Select-Object name, objectClass, distinguishedName | 
        Export-CSV -Path $csvPath -NoTypeInformation
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 18:49:58