feat: Add script to backup group members via csv file
This commit is contained in:
@@ -2,17 +2,26 @@ $global_catalog = Get-ADDomainController -Discover -Service GlobalCatalog
|
|||||||
|
|
||||||
$server = "$($global_catalog.Name):3268"
|
$server = "$($global_catalog.Name):3268"
|
||||||
|
|
||||||
$group = ""
|
$groups = @("", "")
|
||||||
|
|
||||||
$csv_file = "$($group) ($(Get-Date -Format 'yyyy-MM-dd_HH-mm-ss')).csv"
|
$csv_file = "backup_$(Get-Date -Format 'yyyy-MM-dd_HH-mm-ss').csv"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
foreach ($group in $groups) {
|
||||||
$ad_group = Get-ADGroup -Filter 'Name -eq $group -and GroupScope -eq "DomainLocal" -and GroupCategory -eq "Security"' -Server $server -Properties Member -ErrorAction Stop
|
$ad_group = Get-ADGroup -Filter 'Name -eq $group -and GroupScope -eq "DomainLocal" -and GroupCategory -eq "Security"' -Server $server -Properties Member -ErrorAction Stop
|
||||||
$group_members = $ad_group.Member
|
$csv_export_table = @()
|
||||||
$group_members | Export-Csv -Path $csv_file -NoTypeInformation
|
$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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error "Group $group not found"
|
Write-Error "Group $group not found"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$csv_export_table | Export-Csv -Path $csv_file -NoTypeInformation
|
Reference in New Issue
Block a user