【问题标题】:Export azure ad groups membership via powershell通过 powershell 导出 azure 广告组成员资格
【发布时间】:2019-01-15 04:57:09
【问题描述】:

我需要有关 powershell 脚本的帮助。我正在寻找 CSV 文件中多个组的 Azure AD、组成员身份详细信息。

我希望得到的格式是:

组名:SG-Test-Users
成员:xyz、abc 等

Output needed in this format

请帮忙

我尝试了,下面的脚本,但它没有以我正在寻找的格式给出输出。

Import-Csv -Path "C:\temp\testgroup.csv" | ForEach-Object {Get-AzureADGroupMember -ObjectId $_.name | select displayname,userprincipalname} | Export-Csv -Path "c:\temp\outputfile1.csv" -NoTypeInformation

谢谢,

【问题讨论】:

    标签: powershell azure-active-directory azure-powershell


    【解决方案1】:

    试试下面的命令,对我来说效果很好。 注意它会将数据附加到文件而不是覆盖。

    $csv = Import-Csv "C:\Users\joyw\Desktop\testgroup.csv"
    foreach ($line in $csv){
        $groupname = $line.GroupName
        $objectid = (Get-AzureADGroup | Where-Object {$_.DisplayName -eq $groupname}).ObjectId
        Get-AzureADGroupMember -ObjectId $objectid | select DisplayName,UserPrincipalName | Export-Csv -Path "C:\Users\joyw\Desktop\outputfile1.csv" -NoTypeInformation -Append
    }
    

    我的测试文件

    testgroup.csv

    输出文件1.csv

    【讨论】:

    • 实际上,我希望输出也有一个“组名”列,然后是组成员。带有这个的输出只显示成员名称,很难与组匹配。
    • 有人请帮忙回答这个问题。
    【解决方案2】:

    我是新手,但这是我的看法

    在下面尝试(根据需要修改输出),然后将控制台输出保存到文件并按 excel 中的要求进行按摩

    干杯

        $gg=Get-AzureADGroup -top 200
        ForEach ($g in $gg){
            $a = Get-AzureADGroup -ObjectId $g.ObjectId  
            $b = Get-AzureADGroupMember -ObjectId $g.ObjectId -All $true 
            ForEach ($c in $b){ 
                Write-host  $a.DisplayName ";" $c.ObjectId ";" $c.ObjectType $c.UserType ";" $c.UserPrincipalName 
            }
        } 
    

    【讨论】:

      【解决方案3】:
      $ResourceAuditArray = @()
      ForEach ($g in Get-AzureADGroup -SearchString "<first word of groups e.g. DFC, ADF, DAS>"){ 
          $ResourceAuditArray += Get-AzureADGroupMember -ObjectId $g.ObjectId -All $true  | Select-Object ObjectId, ObjectType, UserType, UserPrincipalName, @{n="DisplayName"; e={$g.DisplayName}}
      } 
      
      $ResourceAuditArray | Export-Csv  "<AAD Users list>.Csv"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-02
        • 1970-01-01
        相关资源
        最近更新 更多