【问题标题】:Get Members of AD Group and output in specific manner获取AD组的成员并以特定方式输出
【发布时间】:2019-05-02 23:54:16
【问题描述】:

有很多关于如何从文本文件中获取特定组的成员并将它们输出到 CSV 的指南,我现在精通这些指南,但是它们并不完全符合我的标准和我的知识完全不能让我越过这个界限。

我有以下

$Filename = "C:\Users\Username\Desktop\AD Groups.txt"
$GroupName = Get-Content $Filename

Get-ADGroupMember -identity $GroupName | select name, $GroupName | Export- 
csv -path C:\Temp\Groupmembers.csv -NoTypeInformation

我想要做的是获取文本文件中指定的组中的用户并将它们输出到看起来像这样的 CSV 文件

GroupName    MemberName
Group 1      All the members of that group ...
Group 2      All the members of that group ...

我找到的所有当前版本都这样做

Group Name    MemberName
Group 1       Name1
Group 1       Name 2
Group 2       Name 1
Group 2       Name 2
Group 3       Name 1

等等

【问题讨论】:

    标签: powershell active-directory


    【解决方案1】:

    您可以执行以下操作,这将在一行和一个属性 (MemberName) 下创建一个以分号分隔的成员列表。

    $Filename = "C:\Users\Username\Desktop\AD Groups.txt"
    $GroupNames = Get-Content $Filename
    
    $Output = foreach ($GroupName in $GroupNames) {
        $members = Get-ADGroupMember -Identity $GroupName
        [pscustomobject]"" | Select @{n="GroupName";e={$groupName}},@{n="MemberName"; e={$members.name -join ";"}}
    } 
    
    $Output | Export-Csv -path C:\Temp\Groupmembers.csv -NoTypeInformation
    

    【讨论】:

    • 完美,我添加了 -Recursive 来给我所有的用户,它很有魅力。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多