Hello AJU,
Thank you for your question and for reaching out with your question today.
To fetch the details of specific groups existing in multiple domains in Active Directory using PowerShell, you can use the following script as a starting point. This script assumes that you have the Active Directory PowerShell module installed and you have the necessary permissions to query group information across domains.
```powershell
# List of domains
$domains = @("domain1.com", "domain2.com")
# List of group names to fetch details for
$groupNames = @("Group1", "Group2")
# Loop through each domain
foreach ($domain in $domains) {
Write-Host "Domain: $domain"
# Connect to the domain
Import-Module ActiveDirectory
Set-Location AD:
$domainContext = Get-ADDomain $domain
# Loop through each group
foreach ($groupName in $groupNames) {
$group = Get-ADGroup -Filter {Name -eq $groupName} -Server $domainContext.DistinguishedName
if ($group) {
Write-Host "Group: $($group.Name)"
Write-Host "Created: $($group.Created)"
Write-Host "Description: $($group.Description)"
Write-Host "GroupScope: $($group.GroupScope)"
Write-Host "GroupType: $($group.GroupType)"
Write-Host "SamAccountName: $($group.SamAccountName)"
# Get member of groups
$memberOf = Get-ADGroup -Filter {Member -eq $group.DistinguishedName} -Server $domainContext.DistinguishedName
if ($memberOf.Count -gt 0) {
Write-Host "MemberOf:"
foreach ($memberOfGroup in $memberOf) {
Write-Host " $($memberOfGroup.Name)"
}
} else {
Write-Host "MemberOf: None"
}
$managedBy = $group.ManagedBy
if ($managedBy) {
$managedByGroup = Get-ADGroup $managedBy
Write-Host "ManagedBy: $($managedByGroup.Name)"
} else {
Write-Host "ManagedBy: Not specified"
}
Write-Host
} else {
Write-Host "Group '$groupName' not found in $domain"
}
}
}
Please replace the domain names and group names in the script with your actual domain names and group names. Keep in mind that this script should be executed with administrative privileges and that you need appropriate permissions to query group information in the specified domains. Additionally, you might need to adjust the script to fit your specific environment and requirements.
I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.
If the reply was helpful, please don’t forget to upvote or accept as answer.
Best regards.