feat: Add script to backup group members via csv file

This commit is contained in:
Björn Benouarets
2025-08-13 09:07:54 +02:00
parent 45ec6e3f26
commit ad4125159a

View File

@@ -11,11 +11,15 @@ try {
$ad_group = Get-ADGroup -Filter 'Name -eq $group -and GroupScope -eq "DomainLocal" -and GroupCategory -eq "Security"' -Server $server -Properties Member -ErrorAction Stop
$csv_export_table = @()
$ad_group.Member | ForEach-Object {
$ad_user = Get-ADUser -Identity $_ -Properties * -Server $server
$csv_export_table += [PSCustomObject]@{
Group = $group
MemberEmail = $ad_user.SamAccountName
MemberDistinguishedName = $ad_user.DistinguishedName
try {
$ad_user = Get-ADUser -Identity $_ -Properties * -Server $server -ErrorAction Stop
$csv_export_table += [PSCustomObject]@{
Group = $group
MemberEmail = $ad_user.SamAccountName
MemberDistinguishedName = $ad_user.DistinguishedName
}
} catch {
Write-Error "User $group not found and skipped..."
}
}
}