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