Export all Active Drectory Group's members in Excel

Argomenti vari di carattere sistemistico
Post Reply
daniele
Posts: 342
Joined: 04 Mar 2009, 13:59

Export all Active Drectory Group's members in Excel

Post by daniele »

1) Installare il modulo ImportExcel:

Se non lo hai già installato, puoi installare il modulo ImportExcel utilizzando il comando:

powershell

Code: Select all

Install-Module -Name ImportExcel -Scope CurrentUser

2) Script PowerShell per esportare su Excel:

Code: Select all

# Importa il modulo Active Directory e ImportExcel
Import-Module ActiveDirectory
Import-Module ImportExcel

# Crea una lista per conservare i dati
$groupMembersList = @()

# Ottieni tutti i gruppi e i loro membri
Get-ADGroup -Filter * | ForEach-Object {
    $groupName = $_.Name
    Get-ADGroupMember -Identity $groupName | ForEach-Object {
        $groupMember = [PSCustomObject]@{
            GroupName = $groupName
            MemberName = $_.Name
            SamAccountName = $_.SamAccountName
        }
        $groupMembersList += $groupMember
    }
}

# Esporta i dati in un file Excel
$groupMembersList | Export-Excel -Path "C:\Path\To\Output\GroupMembers.xlsx" -AutoSize
Post Reply